I have a question from Algebraic Geometry by Robin Hartshorne. My question is on the following proof:

Theorem. Let X be a variety and Y \subseteq \mathbb{A}^n be an affine variety. Let x_1, \ldots, x_n be the coordinate functions on \mathbb{A}^n. A map of sets \psi : X \rightarrow Y is a morphism if and only if x_i \circ \psi is a regular function on X for each i=1, \ldots, n.

Proof
(\Rightarrow) If \psi is a morphism then the x_i \circ \psi are regular functions. This is by the definition of a morphism.

(\Leftarrow) Suppose the x_i \circ \psi are regular. Let f=f(x_1, \ldots, x_n) be any polynomial. Then f \circ \psi is also regular on X. Now because the closed sets of Y are defined by the vanishing of polynomial functions and because regular functions are continuous, \psi^{-1} takes closed sets to closed sets. So \psi is continuous. Recall that regular functions on open subsets of Y are locally quotients of polynomials. Hence g \circ \psi is regular where g is a regular function on any open subset of Y. Therefore \psi is a morphism.

I don't understand this sentence:

Now because the closed sets of Y are defined by the vanishing of polynomial functions and because regular functions are continuous, \psi^{-1} takes closed sets to closed sets.

How do we get \psi^{-1} takes closed sets to closed sets? I guess I just don't understand this sentence in the proof. Thank you.