Hello, I'm learning how to program. When I tried running this script I wrote, I get an error saying the instance for the variable ArmorSlot and WeaponSlot are empty.
I'm using Godot 4.0's alpha 14.
This is the scene tree:

This is the Player script:
extends Node2D
var ArmorSlot = $ArmorSlot
var WeaponSlot = $WeaponSlot
func _process(_delta):
if Input.is_action_just_pressed("ui_click"):
pass
if Input.is_action_just_pressed("ui_rightClick"):
equipmentChanged("armorSlot")
func equipmentChanged(equipmentType):
match equipmentType:
"armorSlot":
defense = ArmorSlot.defenseStat
"weaponSlot":
attack = WeaponSlot.attackStat
_:
print("No match found in equimpentChanged function, doing nothing")
Error:
E 0:00:00:0936 @implicit_new: Cannot get path of node as it is not in a scene tree.
E 0:00:00:0936 @implicit_new: Node not found: "ArmorSlot" (relative to "").
I also notice that if I don't create the variables var ArmorSlot and var WeaponSlot, and write the slots with the dollar signs in the equipmentChanged funtion, I don't get an error and it works!:
func equipmentChanged(equipmentType):
match equipmentType:
"armorSlot":
defense = $ArmorSlot.defenseStat
"weaponSlot":
attack = $WeaponSlot.attackStat
_:
print("No match found in equimpentChanged function, doing nothing")
I'm definitely creating the variables for the children wrong, how should I do it correctly? Thank you for taking the time to help!