"invalid access to property of key 'global_rotation' on a base object type of 'node3d'"
That isn’t really the problem, though, as it works when targetObjectX is not null. What I’m trying to do is make it not attempt the code when it is null.
The syntax didn’t chaged for that, is exactly like is in your first example, the error you put after didn’t seems to come from the code you put because says about global_rotation and your code access global_position property, so will be better if you put the exact error that come from this code or put the code that generates the error from your second comentary