receiving error on previous working code

Godot Version

4.6.2

Question

i am working on my first top down game I’m also following a tutorial on YouTube so it doesn’t cover any errors. the issue is that it was working just fine until i added a canvas layer with a control child node and that has a label child node. if there is an easier way of doing this that won’t give me this error or if i am writing something wrong i would have no idea. I tried to learn from the lessons Godot has but they make zero sense to me. I am receiving the error

“_physics_process: Invalid access to property or key “global_position” on a baseobject of type ‘NIL’”

the correlating code its showing for is

“var direction=(player.global_position-global_position).normalized()”

its within a function to spawn enemies:

func _physics_process(_delta: float) → void:
#spawn an enemy
var direction=(player.global_position-global_position).normalized()
velocity=direction*SPEED
move_and_slide()

Did you try finishing this official tutorial series already? Your first 2D game — Godot Engine (stable) documentation in English

Please also check this post with information how to properly format your code on the Forum, so it’s easier for us to understand and how to properly formulate the questions: Posting guidelines in #Help channel

What this error means is that at runtime, player variable is null, meaning is not assigned, while you’re trying to access its global_position, which results in an error.
How do you assign the value to that variable?