Death mechaninic not working properly

I triede to make a system were after my character lost all of it’s HP, a death animation would play and once it was over the secene would change to a death screen, but when I try, I doesn’t work and the player never changes scenes

func _process(delta):
	if Input.is_action_pressed("Kill"):
	if global.hp < 0:
		$"no life")
		$"no life")
		$"no life")
	$Label.text = ("SCORE: " + str(global.score))

func _on_death_timer_timeout():

Once global.hp drops below zero, you call these lines on every frame. You should call them only once.

1 Like

How can I do it?

Just improve it a little bit. Define var death_timer_started = false at the top of the script, the change your code to:

if global.hp < 0 and not death_timer_started:
    // start your animations and the timer
    death_timer_started = true

It’s now working properly, but the animation doesn’t play

You might need to place some await lines between your animations.

	await get_tree().create_timer(3).timeout

Or you could use

await $AnimatedSprite2Danimation_finished

Though I would recommend checking if the signal exists, since I haven’t used animatedsprite2ds