Let $n$ in $\mathbb{Z}_{>1}$ be an integer and $k$ an algebraically closed field. Let $X \subset \mathbb{P}^2_k$ be the curve given by $x_1^n=x_2x_0^{n-1}-x_2^n$. Show that $\mathcal{O}_X(X)=k$.
Could anyone give me a hint? I know the theorem: Let $Y \subset \mathbb{P}^n$ be closed, then $\mathcal{O}_Y(Y)= \{ f:Y \to k| f \; \text{locally} \; \text{constant} \}$. Could I use this theorem for this problem?
Yes, you can. But your theorem is not correct. The counterexample is any closed immersion $\mathrm{Spec}\,k[x]/x^2 \rightarrow \mathbb{P}^n$. I think that the statement should be formulated as follows.
Let $X$ be a reduced closed subscheme in $\mathbb{P}^n$. Then any global regular function on $X$ is locally constant.
Now we use the theorem to show that any global regular function on a connected, reduced closed subscheme in $\mathbb{P}^n$ is constant.
Pick $f\in \Gamma(X,\mathcal{O}_X)$. For given $\alpha \in k$ consider the set
$$U_{\alpha} = \{x\in X\,|\,f(x)=\alpha\}$$
Note that there exists $\alpha \in k$ such that $U_{\alpha}\neq \emptyset$. Pick this $\alpha$. Since $X$ is separated (as a closed subscheme of $\mathbb{P}^n$), we deduce that $U_{\alpha}$ is closed. Since $f$ is locally constant, we know that $U_{\alpha}$ is open. Thus $U_{\alpha}$ is clopen. Therefore, by connectedness of $X$, we deduce that $U_{\alpha} = X$ and hence $f$ is constant.
So it suffices to check, if your subscheme is reduced and connected. I think it is even integral and this can be verified on affine patches of $\mathbb{P}^2$.