The construction of closed subscheme

Let $(\varphi,\varphi^{\sharp}):(X,\mathcal{O}_X)\to (Y,\mathcal{O}_Y)$ be a morphism of schemes.
Suppose $Y$ is covered by a family of affine open subschemes $\{U_i\}$ with $U_i=\mathrm{Spec} A_i$.

Consider $\varphi^{\sharp}(Y):\mathcal{O}_Y(Y)\to \mathcal{O}_X(X)$ and $\rho_{YU_i}:\mathcal O_Y(Y)\to A_i$. Let $S$ be a nonempty subset of $\ker(\varphi^{\sharp}(Y))$ and $\mathfrak p_i$ be the ideal of $A_i$ generated by $\rho_{YU_i}(S)$.

Given $f\in A_i,g\in A_j$, let $\mathfrak q_f$ be the ideal of $(A_i)_f$ generated by $\rho_{YD(f)}(S)$, and $\mathfrak p_j$ be the ideal of $A_j$ generated by $\rho_{YU_j}(S)$, and $\mathfrak q_g$ be the ideal of $(A_j)_g$ generated by $\rho_{YD(g)}(S)$. Then we
have the following two commutative diagrames:

$$\begin{array}[c]{ccc} A_i&{\rightarrow}&A_i/\mathfrak p_i\\ \downarrow&&\downarrow\\ (A_i)_f&{\rightarrow}&(A_i)_f/\mathfrak q_f \end{array}$$

$$\begin{array}[c]{ccc} A_j&{\rightarrow}&A_j/\mathfrak p_j\\ \downarrow&&\downarrow\\ (A_j)_g&{\rightarrow}&(A_j)_g/\mathfrak q_g \end{array}$$

We get two closed immersions $\psi_i:\mathrm{Spec}(A_i/\mathfrak p_i)\to \mathrm{Spec}A_i$ and $\psi_j:\mathrm{Spec}(A_j/\mathfrak p_j)\to \mathrm{Spec}A_j$.

Define $\lambda_i:(A_i/\mathfrak p_i)_{f+\mathfrak p_i}\to (A_i)_f/\mathfrak q_f$ as follows：

$\frac{a+\mathfrak p_i}{f^n+\mathfrak p_i}\mapsto \frac{a}{f^n}+\mathfrak q_f.$

If $\frac{a+\mathfrak p_i}{f^n+\mathfrak p_i}=\frac{b+\mathfrak p_i}{f^m+\mathfrak p_i},$

then there exists some $k\in \Bbb N$ such that $f^k(af^m-bf^n)\in\mathfrak p_i$,

we get $\frac{a}{f^n}+\mathfrak q_f=\frac{b}{f^m}+\mathfrak q_f$, so $\lambda_i$ is defined well.

Obviously $\lambda_i$ is surjective.

If $\frac{a}{f^n}+\mathfrak q_f=0$,then $\frac{a}{f^n}\in \mathfrak q_f, \frac{a}{1}\in \mathfrak q_f$,

we have
$\frac{a}{1}=\frac{x_1}{f^{n_1}}\frac{r_1}{1}+\frac{x_2}{f^{n_2}}\frac{r_2}{1}+\cdots+\frac{x_k}{f^{n_k}}\frac{r_k}{1}$ where $x_t\in A_i,r_t\in \rho_{YU_i}(S),1\le t\le k$.

Multiply both sides by $\frac{f^{n_1+n_2+\cdots+n_k}}{1}$, there exists some $h\in \Bbb N$ such that $af^h\in \mathfrak p_i$, so
$\frac{a+\mathfrak p_i}{f^n+\mathfrak p_i}=0$, and $\lambda_i$ is injective, therefore it is an isomorphism. In the same way we get that
$\lambda_j:(A_j/\mathfrak p_j)_{g+\mathfrak p_j}\to (A_j)_g/\mathfrak q_g$ is also an isomorphism.

We know that $U_i\cap U_j$ can be covered by a family of affine open subschemes $\{ W_{\alpha} \}$ of $Y$ such that
$W_{\alpha}=D(f_{\alpha})=D(g_{\alpha})$, where $f_{\alpha}\in A_i,g_{\alpha}\in A_j$.

Denote $Z_i=\mathrm{Spec}(A_i/\mathfrak p_i),Z_j=\mathrm{Spec}(A_j/\mathfrak p_j)$.
$\forall c\in W_{\alpha}$, if $\psi_i^{-1}(c)\neq \emptyset$, then $c\in \psi_i(Z_i)$, because $\lambda_i,\lambda_j$
are isomorpisms, we also have $c \in\psi_j(Z_j)$. We get $\chi_i:\psi_i^{-1}(U_i\cap U_j)\simeq \psi_i(Z_i)\cap \psi_j(Z_j),\chi_j: \psi_j^{-1}(U_i\cap U_j)\simeq \psi_i(Z_i)\cap \psi_j(Z_j)$ as homeomorphisms of topological spaces. Denote $Z_{ij}=\psi_i^{-1}(U_i\cap U_j), Z_{ji}=\psi_j^{-1}(U_i\cap U_j)$, $\xi_{ij}=\chi_j^{-1}\chi_i, \xi_{ji}=\chi_i^{-1}\chi_j$. Because $\lambda_i,\lambda_j$ are isomorpisms, $\xi_{ij}$ and $\xi_{ji}$ are isomorphisms of schemes，and $\xi_{ij}=\xi_{ji}^{-1}$.

Can we apply the Glueing Lemma to get a closed subscheme $Z$ of $Y$ and a closed immersion $(\mu,\mu^{\sharp}):(Z,\mathcal O_Z)\to (Y,\mathcal O_Y)$? Does there exist a morphism of schemes $(\nu,\nu^{\sharp}):(X,\mathcal O_X)\to (Z,\mathcal O_Z)$ such that $(\varphi,\varphi^{\sharp})=(\mu,\mu^{\sharp})(\nu,\nu^{\sharp})$?