I can't quite follow Chapter III, Example 12.7.2 in Hartshorne (I've written it in the case of affine varieties only here since I haven't worked with schemes in general yet and this is all I need).
In it, he gives an alternative proof of a result I asked about in this question.
Let $X$ be an affine variety over an algebraically closed field $k$, $A=\Gamma(X,\mathcal{O}_X)$, and $\mathcal{F}$ a coherent sheaf on $X$.
Let $x\in X$, $\mathfrak{m}_x=\{f\in A\mid f(x)=0\}$, and $k(x)=A/\mathfrak{m}_x$. Then the function $$\varphi(x)=\dim_{k(x)}(\mathcal{F}\otimes_A k(x))$$ is upper semi-continuous.
I'll go through his reasoning and my thoughts so far. Since $\mathcal{F}$ is coherent, I have taken an $A$-module $M$ with $\mathcal{F}=\widetilde{M}$.
He starts by saying that by Nakayama's Lemma we have that $\varphi(x)$ is the minimum number of generators of the stalk $\mathcal{F}_x$ as an $\mathcal{O}_x$-module.
Here is my attempt to justify this:
Suppose $x_1,\ldots,x_n$ generate $\mathcal{F}_x=M_{\mathfrak{m}_x}$ as an $\mathcal{O}_x=A_{\mathfrak{m}_x}$ module, with $n$ minimal. Then for any $m\in\mathcal{F}_x$ we can find $a_i\in A$, $f\in A\setminus\mathfrak{m}_x$ such that $$m=\frac{a_1}{f}x_1+\cdots+\frac{a_n}{f}x_n$$ (we can assume a common denominator by taking terms into the $a_i$). Since $k(x)$ is a field we can find $g\in A$ with $fg-1\in\mathfrak{m}_x$. Then for $b_i=a_ig$ we have $m=b_1x_1+\cdots+b_nx_n$ in $\mathcal{F}\otimes_A k(x)=M/\mathfrak{m}_xM$ and so $\varphi(x)\leq n$.
Conversely, suppose that $\varphi(x)=l$ and $x_1,\ldots,x_l$ generate $\mathcal{F}\otimes_A k(x)$ over $k(x)$. Now, $\mathcal{F}\otimes_A k(x)=\mathcal{F}_x/\mathfrak{m}_x\mathcal{F}_x$, so by Nakayama's Lemma there exists some $f\in A\setminus\mathfrak{m}_x$ such that the $x_i$ generate $(M_{\mathfrak{m}_x})_f$ as an $A_f$-module. But $(M_{\mathfrak{m}_x})_f=M_{\mathfrak{m}_x}$ since $f\notin\mathfrak{m}_x$, and $A_f\subseteq A_{\mathfrak{m}_x}$, so they certainly generate $\mathcal{F}_x$ as an $\mathcal{O}_x$-module. Then $n\leq\varphi(x)$, so $\varphi(x)=n$ as desired.
He goes on to say that if $x_1,\ldots,x_n$ form a minimal set of generators, then they generate $\mathcal{F}$ in some neighbourhood.
From my justification of the first statement, it appears that this neighbourhood would be $D(f)$. We know they generate $M_{\mathfrak{m}_x}$ as an $A_f$-module, but I'm not sure how this would show they generate $M_f$. I also can't see why we would need to use the minimum number of generators for this step in particular to be true.
He concludes that if we take any $y$ in this neighbourhood, then $\varphi(y)\leq n$.
This is where I am particularly confused. As I understand it (and I may well have already misunderstood something), we would (hopefully) have that $x_1,\ldots,x_n$ generate $M_f$ as an $A_f$-module, with $y\in D(f)$. Then why does this imply that we can generate $\mathcal{F}_y=M_{\mathfrak{m}_y}$ as an $\mathcal{O}_y=A_{\mathfrak{m}_y}$ module using $n$ elements?
Perhaps I'm not using Nakayama's Lemma in the way he intended, my justification seems very laboured in comparison to how it is presented, so I feel I'm really missing something here. Any help would be much appreciated.