How do I fix my code?

Godot Version

Godot 4.7

Question

How do i fix my code so it will not give me this error

Invalid access to property or key ‘global_position’ on a base object of type ‘null instance’?

extends Node
@onready var markA: Marker3D = %Marker3D
@onready var player: CharacterBody3D = %Player
var debug = false
var speedrun = false
var books = 0



func World_changeA():
	player.global_position = markA.global_position
	player.force_update_transform()
func World_changeB():
	pass #get_tree().change_scene_to_file("")
func World_changeC():
	pass #get_tree().change_scene_to_file("")
func Boss_change():
	pass #get_tree().change_scene_to_file("")

Your player is null, you likely didn’t get it’s reference properly. Since you are trying to access it using a unique name, did you make sure to right click on the player node, and select “access as unique name”? And did you also make sure it’s called Player exactly, and not player?

i did ctrl while holding my player and put it in my code and it’s exactly player

Before the code executes try putting a print line to display which variable is coming in null. Then you can figure out where your issue is.

Print(player)
Print(markA)

Like the previous person said, you’ve assigning a property to a target that’s invalid/null. This causes the crash. So find whats causing it to be invalid. Maybe it’s in the player script/ scene, maybe it’s not named correctly in the scene your running, or maybe it’s not even in the scene you’re running!