Queue_free and free not working

Godot 4.2.1

I am doing a course on Godot and am trying to make code where when you click it deletes a node but it keeps giving me an error: " Invalid call. Nonexistent function queue_free in base ‘Nil.’ "
Here is my code:
func _ready():
var sprite=Sprite2D.new()

func _process(delta):
if Input.is_action_just_pressed(“left_click”):

You never assigned sprite, you made it a local variable in _ready, remove the var

1 Like