Using global sections of scheme completion Let $X = \mathbb{P}_k^n$, with $Y$ a positive-dimensional subvariety of $X$ and $k$ algebraically closed, and let $\hat{X}$ denote the completion of $X$ along $Y$. Hartshorne's Exercise II.9.2 is to prove that $\Gamma(\hat{X},\mathcal{O}_\hat{X}) = k$; let's take that as known.
The subsequent exercise is to use this fact to prove the following result: If $f: X \to Z$ is a morphism of $k$-varieties sending $Y$ to a point, then $f$ sends $X$ to a point. 
Several strategies have occurred to me, such as looking at the fibre over the image point or trying to induce some map $\hat{f}: \hat{X} \to \hat{Z}$, but ultimately I have no idea how to use $\Gamma(\hat{X},\mathcal{O}_\hat{X}) = k$ here. Thanks for any hints or advice.
 A: Let me recommend thinking geometrically:
If you have a morphism $X \to Z,$ then functions on $Z$ pull-back to functions on $X$.  So if $X$ doesn't admit many globally defined functions, then whatever the functions on $Z$ are, they must satisfy a lot of relations when they are pulled back to $Z$.
E.g., as a warm-up: suppose $X$ is a connected projective variety, so that $\Gamma(X,\mathcal O_X) = k$.  Then any morphism $X \to Z$ with $Z$ affine is constant.  
Proof: Let $x_1,\ldots, x_n$ be the coordinates on $Z$ (thought of as lying in some $\mathbb A^n$).  They must pull-back to constants on $X$.  If $x_i$ pulls back to the constant $a_i \in k$,
then the image of $X$ is just the single point $(a_1,\ldots,a_n)$ in $\mathbb A^n$. QED
Now to your question: note that $\widehat{X}$ ``lies inside'' any open neighbourhood of $Y$.  More precisely, if $U \subset X$ is an open subset containing $Y$, then the canonical morphism of locally ringed spaces
$\widehat{X} \to X$ factors through a morphism $\widehat{X} \to U \subset X$.  (Indeed, this morphism induces an isomorphism of $\widehat{X}$ with
the completion $\widehat{U}$ of $U$ along $Y$.)
Since the image of $Y$ is a single point $z$ in $Z$, we may find an affine open n.h. $V$ of $z$ in $Z$, whose preimage $U$ is an open n.h. of $Y$.
Thus the composite $\widehat{X} \to U \subset X \to Z$ may be factored as $\widehat{X} \to U \to V \subset Z$.   Now we may apply the same reasoning as in the warm-up exercise to see that $\widehat{X} \to V$ must be constant.  QED
EDIT (in response to question in comments): 
To see that $\widehat{X} \to V$ being constant implies that $X \to V$ is constant, use the fact that $\widehat{X}$ is scheme-theoretically dense in $X$ (because $X$ is irreducible).
The intuition here is that if we take a function on $V$ and pull it back to $X$, we get a function on $X$, which if pulled back further to $\widehat{X}$,
becomes constant (by what we have already proved).  Now restricting functions from $X$ to $\widehat{X}$ corresponds to "expanding $f$ into a formal Taylor series w.r.t. those coordinates on $X$ that are transverse to $Y$", and since $X$ is irreducible, a function on $X$ will be characterized by its Taylor series,
and so, finally, if its Taylor series is constant, the original function will
be constant too.
Here is a precise argument; note that the initial reduction to the affine case allows us to work with rings and completions, so that function theoretic
intuition above becomes rigorous:
Choose an affine open subset $U$ of $X$ such that $U \cap Y \neq \emptyset.$ (In particular, we have chosen $U$ to be non-empty!) Then the pull-back of $U$ under the monomorphism
$\widehat{X} \to X$ is an open formal subscheme of $\widehat{X}$ which
is naturally identified with $\widehat{U}$, the completion of $U$ along
$U\cap Y$.  
Since $\widehat{X} \to V$ is constant, so is $\widehat{U} \to V$ (since
it factors through the inclusion of $\widehat{U}$ in $\widehat{X}$).  We will show that this implies that $U \to V$ is constant.  Since $X$ is irreducible and $U$ is non-empty, it is Zariski dense in $X$, and so $X\to V$ is constant.
It remains to show that if $U \to V$ is a morphism of affine varieties, with $U$ being irreducible, if $\widehat{U}$ is the completion of $U$ along a 
proper closed subset, and if the composite $\widehat{U} \to U \to V$
is constant, than the original map $U \to V$ is constant.
Converting things to rings, we have the following situation: a morphism
$B \to A$ of $k$-algebras, with $A$ a domain, and a proper ideal $I$ of $A$, such that if $\hat{A}$ denotes the $I$-adic completion of $A$,
then the composite $B \to A \to \hat{A}$ factors through some morphism
$B \to k$.   We want to conclude that $B \to A$ also factors through this
morphism $B \to k$.  But this follows from the fact that $A\to \hat{A}$ 
is injective (the Krull intersection theorem).  (And this is where we
use that $A$ is a domain.)
