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

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

Proof

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

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

I don't understand this sentence:

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

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