Audio keeps repeating (Loop is off)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Rayu

I’ve made a soundeffect and when my game hits its time to 0 i call that soundeffect.
This is My Script for the Control Timer:

func _process(delta):
	if Globals.timeLeft > 0:
		Globals.timeLeft -= delta
		$TimerCount.text = str(Globals.timeLeft)
		$TimerCount.text = "%d" % Globals.timeLeft
		Globals.timeLeft = 0
        get_tree().call_group("Playeres", "game_over")
		get_tree().call_group("Enemies", "game_over")
		get_tree().call_group("GameOverGroup", "game_over")

It plays the Audio but it keeps giving a bug sound, always repeating and not playing the Audio fully.

:bust_in_silhouette: Reply From: jgodfrey

It’s hard to say without more code, but…

With the code you posted, when your Globals.timeLeft value is <= 0, you’ll start processing the else side of that code block. There, you set Globals.timeLeft = 0, play some music, and do some other things.

Now, until something resets Globals.timeLeft to a positive value again, every frame will process that else block of code. So, it’ll continue to set Globals.timeLeft = 0, start playing your music again, and everything else there.

I’m not sure what the intent is here, but I assume you don’t want to reprocess that else block in every frame after your counter reaches 0 - which is what’s happening now.