How to play music after player death

What do the error messages say in your debugger?




Have you checked the sound itself, if its 3 times the same sound in on file?

I will check

in the sound file there is 1 time repeating not 3 and i was wrong in my menu scene there is no audio player its just in autoload(bg music) but i dont think its the problem

https://pixabay.com/sound-effects/search/pop/
My pop sound is the second one.

Maybe godot bug?

Can paste your Game.gd-script here?

I am going to sleep now, and sorry i cant give you the game gd code but the part you can see there in these screenshot,so see you tomorrow!

1 Like

Hi, thats my game.gd code

extends Node2D


const SPAWN_INTERVAL = 0.4 # Adjust spawn interval as needed
var spawn_timer = 0.0
var can_spawn_bullets = true
onready var deathsound = $Pop

func _process(delta):
	spawn_timer += delta
	if spawn_timer >= SPAWN_INTERVAL:
		spawn_bullet()
		spawn_timer = 0.0
		
signal fade_out

func spawn_bullet():
	if not can_spawn_bullets:
		return
		
	var bullet_scene = preload("res://Scenes/Bullet.tscn")
	var bullet_instance = bullet_scene.instance()
	var viewport_width = get_viewport().size.x
	bullet_instance.position.x = rand_range(0, viewport_width)
	connect("fade_out", bullet_instance, "fade_out")
	get_tree().root.add_child(bullet_instance)
	

func playerDied(pop_effect_instance) -> void:
	print("Player died") 
	if not deathsound.playing:
		deathsound.play()
	can_spawn_bullets = false  # Stop spawning bullets
	add_child(pop_effect_instance)
	emit_signal("fade_out")
	$AnimationPlayer.play_fade_out()
	yield(get_tree().create_timer(3), "timeout")
	get_tree().change_scene("res://Scenes/Menu.tscn")
	
func _ready() -> void:
	deathsound.connect("finished", self,"audio_finished")

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


what about the pop_effect_instance? Does it play a sound?

No its the pop effect(particle)

I dont know why but the audio finished text doesn’t appear in console,i think func audio finished is not working

Whats inside the fade_out animation in the animation-player?

My enemy’s animation with modulate

okay. Add a script to your Pop-AudioStreamPlayer:

func play(from_position: float = 0.0) -> void:
    print("Start-Playing")
    super.play(from_position)

And test how often that gets printed

1 Like

bruhhhhh the same error i deleted this and now it giving me this

with this when i added to my pop (audio) a script there extends particle 2d but i was attached it to the audio player

[gd_scene load_steps=18 format=2]

[ext_resource path=“res://Scenes/Player.tscn” type=“PackedScene” id=1]
[ext_resource path=“res://Scenes/Bullet.tscn” type=“PackedScene” id=2]
[ext_resource path=“res://Scenes/Background.tscn” type=“PackedScene” id=3]
[ext_resource path=“res://Scenes/Enemy.tscn” type=“PackedScene” id=4]
[ext_resource path=“res://Scenes/Game.gd” type=“Script” id=5]
[ext_resource path=“res://Scenes/pop.tscn” type=“PackedScene” id=6]
[ext_resource path=“res://Scenes/Timer.tscn” type=“PackedScene” id=7]
[ext_resource path=“res://Scenes/Borders.tscn” type=“PackedScene” id=8]
[ext_resource path=“res://Scripts/Pop.gd” type=“Script” id=9]
[ext_resource path=“res://Scripts/Highscore.gd” type=“Script” id=10]
[ext_resource path=“res://Fonts/Flippinfont-KVdeo.ttf” type=“DynamicFontData” id=11]
[ext_resource path=“res://Scripts/AnimationPlayer.gd” type=“Script” id=12]

[sub_resource type=“GDScript” id=4]
script/source = "extends Particles2D

"

[sub_resource type=“DynamicFont” id=1]
size = 80
font_data = ExtResource( 11 )

[sub_resource type=“Animation” id=2]
resource_name = “Fade_out”
tracks/0/type = “value”
tracks/0/path = NodePath(“.:modulate”)
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
“times”: PoolRealArray( 0, 1 ),
“transitions”: PoolRealArray( 1, 1 ),
“update”: 0,
“values”: [ Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ) ]
}
tracks/1/type = “value”
tracks/1/path = NodePath(“…/Highscore:modulate”)
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
“times”: PoolRealArray( 0, 1 ),
“transitions”: PoolRealArray( 1, 1 ),
“update”: 0,
“values”: [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ) ]
}

[sub_resource type=“Animation” id=3]
length = 0.001
tracks/0/type = “value”
tracks/0/path = NodePath(“.:modulate”)
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
“times”: PoolRealArray( 0 ),
“transitions”: PoolRealArray( 1 ),
“update”: 0,
“values”: [ Color( 1, 1, 1, 1 ) ]
}
tracks/1/type = “value”
tracks/1/path = NodePath(“…/Highscore:modulate”)
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
“times”: PoolRealArray( 0 ),
“transitions”: PoolRealArray( 1 ),
“update”: 0,
“values”: [ Color( 1, 1, 1, 0 ) ]
}

[node name=“Game” type=“Node2D”]
position = Vector2( 396, 441 )
script = ExtResource( 5 )
meta = {
edit_horizontal_guides”: [ 500.0 ],
edit_vertical_guides”: [ 500.0 ]
}

[node name=“Borders” parent=“.” instance=ExtResource( 8 )]
position = Vector2( -396, -440 )

[node name=“Player” parent=“.” instance=ExtResource( 1 )]
position = Vector2( 100, 100 )
z_index = 5

[node name=“popeffect” parent=“Player” instance=ExtResource( 6 )]
position = Vector2( 0, -6 )
script = SubResource( 4 )

[node name=“Enemy” parent=“.” instance=ExtResource( 4 )]
position = Vector2( 104, 489 )
collision_layer = 4

[node name=“Bullet” parent=“.” instance=ExtResource( 2 )]
position = Vector2( 1044, 33 )
collision_layer = 2

[node name=“Timer1” parent=“.” instance=ExtResource( 7 )]
margin_left = 73.0
margin_top = -364.0
margin_right = 133.0
margin_bottom = -264.0
align = 1
valign = 1

[node name=“Highscore” type=“Label” parent=“.”]
modulate = Color( 1, 1, 1, 0 )
margin_left = -98.0
margin_top = 237.0
margin_right = 285.0
margin_bottom = 388.0
custom_fonts/font = SubResource( 1 )
text = "Highscore "
align = 1
valign = 1
script = ExtResource( 10 )

[node name=“Background” parent=“.” instance=ExtResource( 3 )]
position = Vector2( -396, -439 )
z_index = -5
meta = {
edit_lock”: true
}

[node name=“AnimationPlayer” type=“AnimationPlayer” parent=“.”]
root_node = NodePath(“…/Enemy”)
anims/Fade_out = SubResource( 2 )
anims/RESET = SubResource( 3 )
script = ExtResource( 12 )

what i shuold remove ?

delete this
[ext_resource path=“res://Scripts/Pop.gd” type=“Script” id=9]

i have to go to work now. ill come back later

1 Like