How to play music after player death

yes, put a print(“Player died”) inside of the method, before “yield”

i tried

Which scene contains the deathsound?

Only my game scene

and it plays 3 times in a row or at the same time?

Yeah🤷 i dont now why

Whats inside the bullet scene?

extends Area2D

const min_bullet_speed = 200
const max_bullet_speed = 500
# Speed of the bullet
var BULLET_SPEED = 300

# Maximum angle deviation from vertical (in degrees)
const MAX_ANGLE_DEVIATION = 30

# Called when the node enters the scene tree for the first time.
func _ready():
	# Set the initial position of the bullet (random x at the bottom of the screen)
	randomize()  # Ensure random number generation is initialized
	
	var viewport_width = get_viewport().size.x
	position = Vector2(rand_range(0, viewport_width), get_viewport().size.y)
	
	# Apply a random angle deviation
	rotation = deg2rad(rand_range(-MAX_ANGLE_DEVIATION, MAX_ANGLE_DEVIATION))
	BULLET_SPEED = rand_range(min_bullet_speed, max_bullet_speed)
	connect("area_entered", self, "_on_area_entered")

	

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	# Move the bullet upwards at the given angle
	position.y -= BULLET_SPEED * delta * cos(rotation)
	position.x += BULLET_SPEED * delta * sin(rotation)
	
	# Check if the bullet is out of the screen
	if position.y < -100 or position.x < 0 or position.x > get_viewport().size.x:
		queue_free()  # Destroy the bullet when it goes out of screen
		
func fade_out() -> void:
	var tween = Tween.new()
	add_child(tween)
	tween.interpolate_property(self, "modulate", Color(1, 1, 1, 1), Color(1, 1, 1, 0), 1)
	tween.start()
	print("fade_out")

Go to your Game.gd script and test this:

func _ready() -> void:
    deathsound.connect("finished", self "audio_finished")

func audio_finished() -> void:
    print("Audio finished")

and see how often this gets printed

1 Like


why there is an error if i am using “”

You missed a " , " between self and “audio_finished”

Ok but its the same 3 times

Does this message get printed 3 times?

apparently the deathsound never plays. Do you have other audioplayers?

Yeap,on my menu scene

And what sounds does the menu-player play?

My Background music

And those are the only audioplayers in your whole project?

Yes one in my scene(bg music) the other one in game scene(deathsound)