How to make a sprite disappear after seconds

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

I’m totally new about this engine .
I wanted to make a sprite disappear after 1~2 second so I did it like

extends Sprite
var timer
var sprite
func_ready():
$Sprite.visible = true
var t = rand_range(1,2)
yield(get_tree).create_timer(t),“timeout”)
$Sprite.visible = false
and then it got an error (get_node:Node not found :Sprite

How can I solve this problem?

:bust_in_silhouette: Reply From: kidscancode

The error says just what the problem is - there’s no node named “Sprite” attached to this one. $Sprite means the same thing as get_node("Sprite"), which translates to “Get a child of this node named ‘Sprite’”.

It appears you have this script on your Sprite node, so of course there’s no child also called “Sprite”. If this script is on the sprite that you want to hide, then you don’t need to get any node, and you can just say

visible = false