Quick answer: An AudioStreamPlayer plays one sound at a time: calling play() again restarts it. Raise Max Polyphony on the player so overlapping plays layer, or use a small pool of players. A sound that stops when an enemy dies was playing on a node that was freed — play it from a player that outlives the enemy.

Fire five shots quickly and you hear one. Kill an enemy and its death sound stops after a few milliseconds. Both have the same root: one player node can only do so much, and it dies with its parent.

Cause 1: play() restarts the sound

By default, AudioStreamPlayer.play() stops whatever that player was playing and starts again from the beginning. For rapid repeats, set Max Polyphony (available on AudioStreamPlayer, 2D and 3D in Godot 4) to the number of overlapping copies you want:

$ShotSound.max_polyphony = 6
$ShotSound.play()     # now layers instead of restarting

When the limit is reached, the oldest voice is cut, which is usually what you want for gunfire.

Cause 2: the node is freed while playing

func die():
    $DeathSound.play()
    queue_free()      # the sound dies with the enemy at the end of this frame

Play it on something that survives. A simple pattern is a one-shot player added to the level:

func play_detached(stream: AudioStream, pos: Vector2):
    var p := AudioStreamPlayer2D.new()
    p.stream = stream
    p.global_position = pos
    get_tree().current_scene.add_child(p)
    p.finished.connect(p.queue_free)
    p.play()

Or keep an audio manager autoload with a pool of players and hand sounds to the first idle one.

Cause 3: one player shared by different sounds

Assigning a new stream to a player that is already playing cuts off the current sound. Give each sound category its own player, or use an AudioStreamPolyphonic stream, which can play many different streams through one player:

$SFX.stream = AudioStreamPolyphonic.new()
$SFX.play()
var playback := $SFX.get_stream_playback() as AudioStreamPlaybackPolyphonic
playback.play_stream(preload("res://sfx/coin.ogg"))

Cause 4: too many voices at once

Hundreds of simultaneous sounds become noise and cost CPU. Limit how often the same sound can start (for example, ignore repeats within 30 ms), and use an AudioStreamRandomizer to vary pitch and samples so repeated sounds do not phase.

Cause 5: 3D/2D attenuation

Positional players can appear to cut out because the listener moved out of range (max_distance), not because they stopped. Check with a non-positional AudioStreamPlayer to tell the two apart.

Related fixes