Let $X$ be a variety, $Y \subset \mathbb{A}^n$ an affine variety and $\psi:X \rightarrow Y$ a map such that $x_i \circ \psi$ is a regular function. We want to show that $\psi$ is a morphism of varieties. Since regular functions form a ring, then for any polynomial $f \in k[x_1,\cdots,x_n]$ we have that $f \circ \psi$ is regular and so $\psi$ is continuous. Now we need to show that if $g$ is a regular function on $Y$, then for any open set $V$ of $Y$ the function $g \circ \psi: \psi^{-1}(V) \rightarrow k$ is regular. Hartshorne says that this follows since $g$ is locally a quotient of polynomials.
Here is my "objection": to show that $f \circ \psi$ is regular, we need to show that it is locally a quotient of polynomials, where the polynomials correspond to the "correct" ambient space of $X$. For example, if $X$ is a projective variety, then we need $f \circ \psi$ to be a quotient of homogeneous polynomials of equal degree. In other words, $f \circ \psi$ is locally a quotient of polynomials only after passed through $\psi$... So, what am i missing here?