Attempt to call function 'play' in base 'null instance' on a null instance.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ceo-Potato

i’m gaving an error and i tried everything and it doesn’t work
here is my code:

# checks the state of the player aka skin
func skin_change():
	loader()
	if player_skin == 0:
		$AnimationPlayer.play("duck_collision")
		if !is_on_floor():
			$AnimatedSprite.play("duck_jump")
		else:
			$AnimatedSprite.play("duck_run")
	
	elif player_skin == 1:
		$AnimationPlayer.play("goose_collision")
		if !is_on_floor():
			$AnimatedSprite.play("goose_jump")
		else:
			$AnimatedSprite.play("goose_run")
:bust_in_silhouette: Reply From: SteveSmith

It’s difficult to answer because you don’t say which line has the error, but either $AnimatedSprite or $AnimationPlayer doesn’t exist relative to the node which has this code.

the error is at “$AnimationPlayer.play(“duck_collision”)”

Ceo-Potato | 2023-01-15 09:33

It’s $AnimationPlayer then.

SteveSmith | 2023-01-15 09:44