Definition of $\mathbb{A}^n_S$ by glueing In Eisenbud and Haris (Geometry of schemes I.2.4), if $S=\cup_\alpha U_\alpha$ with the $U_\alpha$ affines, to define $\mathbb{A}^n_S$ one take $X=\cup_\alpha \mathbb{A}^n_{U_\alpha}$ with $\mathbb{A}^n_{U_\alpha}=\operatorname{Spec} R_\alpha[X_1,\ldots,X_n]$.
Then the idea is to glue along the $U_\alpha\cap U_\beta$ but $U_\alpha\cap U_\beta$ is not affine so $\mathbb{A}^n_{U_\alpha\cap U_\beta}$ has no meaning and even if $U_\alpha\cap U_\beta$ is affine, the induced morphism $\varphi_{\alpha,\beta}:\mathbb{A}^n_{U_\alpha \cap U_\beta}\to\mathbb{A}^n_{U_\alpha}$ is not an open immersion so $X_{\alpha,\beta}:=\varphi_{\alpha,\beta}(\mathbb{A}^n_{U_\alpha \cap U_\beta})\not\simeq\mathbb{A}^n_{U_\alpha \cap U_\beta}$ so $X_{\alpha,\beta}\not\simeq X_{\beta,\alpha}$.
So the question is: how to glue the $\mathbb{A}^n_{U_\alpha \cap U_\beta}$ to build $\mathbb{A}^n_S$?
Edit: for $U_\gamma\subseteq U_\alpha$ affine one take the notation $\psi_{\alpha,\gamma}$ the induced morphism $\mathbb{A}^n_{U_\gamma}\to\mathbb{A}^n_{U_\alpha}$.
I have the idea to take $X_{\alpha,\beta}=\cup_\gamma X_{\alpha,\gamma}$ where $X_{\alpha,\gamma}=\psi_{\alpha,\gamma}(\mathbb{A}^n_{U_\gamma})$ and the $\gamma$ so that $U_\gamma\subseteq U_\alpha\cap U_\beta$ affines. Then if (1) the $\psi_{\alpha,\gamma}$ are open immersion then for all $\gamma$ one has $X_{\alpha,\gamma}\simeq X_{\beta,\gamma}$. But I don't see (2) how to conclude that $X_{\alpha,\beta}\simeq X_{\beta,\alpha}$ because the $X_{\alpha,\gamma}$ are only a covering of $X_{\alpha,\beta}$ and not a topology basis and so it is not enough (isn't?).
For the point (1) I see that if $(U_\alpha)_f\subseteq U_\alpha$ the $\mathbb{A}^n_{(U_\alpha)_f}\to \mathbb{A}^n_{U_\alpha}$ is an open immersion. But it is not enough because $(U_\alpha)_f$ has no reason to be a $(U_\beta)_g$.
So questions are
1) why the $\psi_{\alpha,\gamma}$ are open immersion?
2) how to conclude that $X_{\alpha,\beta}\simeq X_{\beta,\alpha}$?
 A: ... and 3): How to verify the cocycle condition?
Here is how to do all this without pain: Use the functorial point of view on schemes.
Consider the functor $(\mathrm{Sch}/S)^{\mathrm{op}} \to \mathsf{Set}$ defined by $T \mapsto \Gamma(T,\mathcal{O}_T)^n$ (forgetting the ring structure on global sections). We claim that it is representable and the representing object will be our $S$-scheme $\mathbb{A}^n_S$; this is the conceptual definition/characterization of $\mathbb{A}^n_S$. There is a general criterion when such a functor is representable, see EGA I (1971), Chap. 0, Corollaire 4.5.5:
The functor has to be a sheaf when restricted to the open subsets of any fixed $S$-scheme and the functor has to be locally representable in the sense that there is an open covering $S = \bigcup_i S_i$ such that each restricted functor on $(\mathrm{Sch}/S_i)^{\mathrm{op}}$ is representable. The sheaf condition is trivial. For the local representability, take any open affine covering $S = \bigcup_i S_i$ and observe that each restricted functor is represented by the already known affine space $\mathbb{A}^n_{S_i}$ over the affine base $S_i$.
The mentioned criterion is very useful also for other constructions, e.g. fiber products, Spec for quasi-coherent algebras, Proj for graded quasi-coherent algebras. For more on this, you might read Brian Osserman's "Fiber products and Zariski sheaves", pdf. By the way, if you already know fiber products, you might as well construct $\mathbb{A}^n_S$ as $\mathbb{A}^n_{\mathbb{Z}} \times_{\mathbb{Z}} S$.
Alternatively, for every locally ringed space $S$, we can construct a locally ringed space $\mathbb{A}^n_S$ over $S$ explicitly, which represents the functor $\mathsf{LRS}/S \to \mathsf{Set}$, $T \mapsto \Gamma(T,\mathcal{O}_T)^n$. The underlying set is the set of pairs $(s,\mathfrak{p})$, where $s$ is a point in $S$ and $\mathfrak{p}$ is a prime ideal in $\mathcal{O}_{S,s}[T_1,\dotsc,T_n]$. If $U \subseteq S$ is open and $f \in \mathcal{O}_S(U)[T_1,\dotsc,T_n]$, then we consider the subset of those $(s,\mathfrak{p})$ for which $s \in U$ and $f_{s} \in \mathcal{O}_{S,s}[T_1,\dotsc,T_n]$ (we take stalks for each coefficient) is not contained in $\mathfrak{p}$. These sets constitute the basis for a topology. The structure sheaf is defined in such a way that the stalk at $(s,\mathfrak{p})$ is $\mathcal{O}_{S,s}[T_1,\dotsc,T_n]_\mathfrak{p}$. The complete definition is a bit complicated, but sections consist of families of stalks which locally come from a fraction in $\mathcal{O}_S(U)[T_1,\dotsc,T_n]_f$. More generally, for every $\mathcal{O}_S$-algebra $A$ we may explicitly construct the (relative) spectrum $\mathrm{Spec}_S(A)$; the above being the special case $A=\mathcal{O}_S[T_1,\dotsc,T_n]$.
