Invalid get index 'global_position' (on base: 'null instance'). error

godot-4
im doing my game and that happens

Invalid get index ‘global_position’ (on base: ‘null instance’).

my is godot-3

that code

extends StaticBody2D

const ProjectileScene := preload(“res://projectile/Projectile.tscn”)

export var player_path := NodePath()
onready var _player := get_node(player_path)

onready var _weapon := $Weapon
onready var _projectile_spawner := $Weapon/ProjectileSpawner

onready var _timer := $Timer

func _ready() → void:
_timer.connect(“timeout”, self, “_shoot”)

func _physics_process(delta: float) → void:
_weapon.look_at(_player.global_position)

func _shoot() → void:
var projectile := ProjectileScene.instance()
projectile.position = _projectile_spawner.global_position
projectile.direction = _weapon.global_position.direction_to(_projectile_spawner.global_position)
add_child(projectile)

someone can help me?

onready var _projectile_spawner := $Weapon/ProjectileSpawner

this one is somehow returning null, can you check the node names as you may have renamed the nodes?
As an alternative, could you Access the node’s unique name and use that instead?

  • Access as Unique Name → Drag’n Drop the node into your script

Also please set the correct tags. The tag of this topic says godot-4 but inside the description, you wrote that this is a script for godot-3?