Error : Invalid set index 'animation' (on base: 'Nil') with value of type 'String'

Godot 4

Question

I am setting up a script so that when the Player touches the endPoint, it will play an animation but i get the error at the top.

extends Node

var points = 0
func addPoints():
	points += 1
	print(points)

func endLevel():
	print("End Level")
	PlayerAnimated.animation = "Disapear"    <<Right here is where the error occurs
	await get_tree().create_timer(5.0).timeout
	print("End again")

The end and end again is to make sure the game gets to that point

I set up an autoload for it name PlayerAnimated and make the animated sprite its own scene

is PlayerAnimated, the autloaded scene have an AnimatedSprite2D or AnimationPlayer as the root node?

Make sure to paste your scripts with formatting, using three ticks, or the </> to make these ticks

```
type or paste code here
```

1 Like

AnimatedSprite2D

is PlayerAnimated ever deleted?

No It is not deleted

Maybe the Autoload wasn’t set up correctly then. If it isn’t queue_free()'d anywhere then it should be giving a syntax error, but once it reaches this section PlayerAnimated == null.

Yeah idk, i might just scrap it and start over because its the first game iv made without a tutorial