Given an algebraically closed field $k$ and a scheme $Z$ over $k$. Consider the projective scheme $X=\mathbb{P}^1_Z=\mathbb{P}_k^1\times_kZ$ and $Y\subset X$ a closed subscheme. Assume that $Y$ does not contain any closed fibre of the projection $p:X\rightarrow Z$, try to show that $\pi:=p|_Y:Y\rightarrow Z$ is an affine morphism, i.e. one can find an affine covering $\{U_i\}$ of $Z$ such that each $\pi^{-1}(U_i)$ is affine.
My attempt:
In the extremely special case $Z=\text{Spec}(k)$, one has $X=\mathbb{P}_k^1$ and $X_z\cong\mathbb{P}_k^1$. Here any closed subscheme $Y$ of $X$ satisfies the condition that $X_z\not\subseteq Y$. So we want the canonical map $Y\hookrightarrow\mathbb{P}_k^1$ to be affine, which is clearly true.
Now let $Z=\text{Spec}(A)$ over $k$, we also have $X_z\cong\mathbb{P}_k^1$ and now $X=\mathbb{P}_A^1$. We know that any closed subscheme of $\mathbb{P}_A^1=\text{Proj}(A[x_0,x_1])$ is determined by a homogeneous ideal $I\subset A[x_0,x_1]$, i.e. $$Y=V_+(I)=\text{Proj}(A[x_0,x_1]/(I))$$ Then I want to define a scheme $Y_k$ such that $Y=Y_k\times_kZ$. If I can do it, them I am done. However, I have no ideal how to apply the setting $X_z\not\subseteq Y$ here.