zariski continuous function with regular restrictions that is not regular in any exponent

I've been stuck on this for a few days.

I'm supposed to find an example of a continuous function $f$ (with values in the field) defined on an affine variety $V=V_1\cup V_2$ with two irreducible components, such that the restrictions to each component is regular, but $f^n$ is not regular for all $n\geq1$.

This doesn't exist in one dimension, so I tried finding such an example by playing with plane curves that are tangent, and considered various functions on each component like the restrictions of projections on different coordinate axes. but I had no success, other than finding a function that is not regular, but it's square is regular, so it's not enough (like the one described by Georges).

A follow-up question that interests me, if those two components are disjoint, would it then have to be regular? (Answer: yes, see Georges comment)

what if they intersect in sufficiently nice ways, would the function have to be regular? I just don't know where to start looking, so some criteria might help.


Let $V=V(Y(Y-X^2))\subset \mathbb A^2=\operatorname {Spec} k[X,Y]$ be the plane curve with irreducible components $V'=V(Y), V''=V(Y-X^2)$ and with ring of regular functions $k[x,y]=k[X,Y]/\langle Y(Y-X^2)\rangle$.
The function $x$ on $V'$ and $y$ on $V''$ glue to a continuous function $\phi:V\to k$ but
Claim:
The function $\phi$ is not regular on $V$.

Indeed, any regular function on $V$ can be written uniquely as $$f(x,y)=p(x)+yq(y)+xyr(x)\quad (\star)$$ for some polynomials in one variable $p,q,r$.
In order for $f(x,y)$ to have a restriction to $V'=V(y)$ equal to $x$ we must have $p(x)=x$ (set $y=0$ in $(\star)$) so that $$ f(x,y)=x+yq(y)+xyr(x)\quad (\star \star) $$
In order for $\phi$ moreover to restrict to $y$ on $V''=V(y-x^2)$ we must also have $x^2=x+x^2q(x^2)+x^3r(x)$ on $k[V'']=k[x]$ (set $y=x^2$ in $(\star \star) $).
But the equality $x^2=x+x^2q(x^2)+x^3r(x)$ is impossible in $k[x]$, so that $f$ does not exist and the claim is proved.

An explanation
If you know scheme theory, the reason for this phenomenon is that the scheme-theoretic intersection of $V'$ and $V''$ is not the origin but the origin with non reduced structure: $V'\cap V''=\operatorname {Spec} \frac {k[x]}{\langle x^2\rangle }$.
The functions $x$ on $V'$ and $y$ on $V''$ do not coincide on $S$: they are equal respectively to $x$ and $0$ and thus they cannot be glued to a regular function on $V$.