Problem displaying text before triggering a wait timer

Godot Version

4.2.2

Question

I have a problem where, when I try to make a timer for my “you died” text to show up before I change to main menu scene, the number displayed stops at 10 (one click before it should go to 0). No matter how many times I click it won’t change.

I feel like this has to do with it going to the wait timer too quickly or something but idk I’m super new to coding.

func _process(_delta):
	if Input.is_action_just_pressed("get_hit(fortesting)"):
		health -= 10
		if health <= 0:
			health = 0
			you_died_scene.visible = true
			await get_tree().create_timer(2.0).timeout
			get_tree().change_scene_to_file("res://Scenes/main_menu.tscn")
		print(health)
		health_label.text = "Health: " + str(health)

Put this line of code before you check health is zero

1 Like

What line of code?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.