I made a script where if you press enter, a sound plays but if you do it keeps playing after its finished,

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

 func _process(_delta):
if Input.is_action_just_pressed("ui_accept"):
	play()
func _on_PressEnter_finished():
 stop()

Even with the func _on_PressEnter_finished, It still loops!

Has the file been imported with Loop? Select the file in the filesystem window then check the import window.

petermoyle | 2022-09-09 17:03

You wouldn’t need to call stop after playback is finished anyway (as it has already stopped).

To add petermoyle’s comment, .mp3 and .ogg files are imported with loop enabled by default (while .wav has it disabled). You can change default for new files on import tab as well. The import tab is found next to scene hierarchy tab.

aXu_AP | 2022-09-09 20:37