Sheaf of a Closed Subset I’ve been given the following definition:

Let $(X,\mathcal{O}_X)$ be a ringed space which is locally isomorphic to an affine algebraic variety, and $Y\subseteq X$ be closed. Then for an open $V\subseteq Y$, set
  $$\begin{align*}
\mathcal{O}_{0,Y}(V)=\{f:V\to k\mid{}&\exists U\subseteq X\text{ open such that }U\cap Y=V\\
&\text{and } g\in\mathcal{O}_X(U)\text{ such that } g\vert_V=f\}
\end{align*}$$
  This defines a presheaf $\mathcal{O}_{0,Y}$ on $Y$, but not, in general, a sheaf.

However I’m struggling to come up with an example where this fails to be a sheaf.

I thought I'd found a counterexample with $X=\mathbb{C}^2$, $Y=V(xy)$, $U=D(x)\cap Y$ and $V=D(y)\cap Y$. Then $U\cap V=\varnothing$, and so if $\mathcal{O}_{0,Y}$ were a sheaf, then we would be able to glue to make a function on $U\cup V$ which is say $1$ on $U$ and $-1$ on $V$.
I can show that we can't get such a function from gluing two functions on $D(x)$ and $D(y)$, but we can take $\frac{x+y}{x-y}$ on $D(x-y)$ to give the required function. Then it isn't enough to just check the 'obvious' open cover, and I haven't yet been able to find a counterexample which works for every one.

Any help would be much appreciated.
 A: This is kind of messy and could probably be written better, but I think this works:
Take $X$ to be the line with "double origin", that is, we define $X$ by gluing two copies of $\Bbb A^1$ together along the open subset $\Bbb A^1\smallsetminus\{0\}$ (with identity as the isomorphism we identify these open subsets). Because I will want to refer to the copies of $\Bbb A^1$, let $X_0$ and $X_1$ denote our two copies of $\Bbb A^1$, which are now naturally identified with open subsets of $X$, and let $O_0,O_1$ denote the two "origins", so $O_i\in X_i$.
Note now that $\{O_0\}=X\smallsetminus X_1$, so $O_0$ is a closed point, and similarly $O_1$ is a closed point. Take $Y:=\{O_0,O_1\}$, which is then a closed subset and the subspace topology is the discrete topology, so $\{O_0\}$ and $\{O_1\}$ are open subsets of $Y$. Then we can look at constant map $f_i:\{O_i\}\to k$ sending $O_i\mapsto i$, and it's not hard to check this gives us an element of $\mathcal O_{0,Y}(\{O_i\})$.
We claim $f_0,f_1$ will not glue to an element of $\mathcal O_{0,Y}(Y)$. If they do, say $f\in\mathcal O_{0,Y}(Y)$, then by definition there is an open subset $U$ of $X$ which contains $Y$ and an element $g\in\mathcal O_X(U)$ such that $g|_Y=f$. But by definition of a sheaf, because $X_0$ and $X_1$ cover $X$, an element $g\in\mathcal O_X(U)$ is the same thing as a pair of elements $g_i\in\mathcal O_X(U\cap X_i)$ for $i=0,1$ which are equal on the intersection. 
Now, because $X_0$ is really just $\Bbb A^1$, the complement of $U\cap X_0$ in $X_0$ is a finite set of points $a_1,\dots,a_m$. Therefore $g_0$ is just a ratio of two polynomials, the denominator of which does not vanish at any $a_i$, and we can write $g_1$ in the same way. But these two agree on the overlap, which consists of infinitely many points (we should assume we are over $\Bbb C$ or any other algebraically closed field here), so you can try to use this to conclude that the expressions which define $g_0$ and $g_1$ are rational functions are in fact equal (you should use the fact that if two polynomials agree on an infinite subset, then they are equal), so $g_0$ and $g_1$ should be equal everywhere they are defined (and in particular, on $Y$). But we also have
$$g_i|_{\{O_i\}}=(g|_{X_i})|_{\{O_i\}}=g|_{\{O_i\}}=(g|_Y)|_{\{O_i\}}=f|_{\{O_i\}}=f_i,$$
and because $f_0$ and $f_1$ take different values at our two origins this is impossible.
