I think you don't have the Position2D as a direct child of the node that has this script. You may have to add it to your scene, or just add another path.
for example instead of the commend "$Position2D" you may have to use:
I'm just saying, that you can't call a properity of a node, if it doesn't exists on the path, that you're giving to the function.
With this little information i could only guess the answer, but I hope it helped ;)