How do I have a sound play when my button is pressed?

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

here is my current code;

func _on_start_button_pressed(): $CenterContainer/VBoxContainer/ yield($CenterContainer/VBoxContainer/boom, "finished") get_tree().change_scene(next_world)

that currently plays the sound and waits until the sound has finished playing before moving onto the next scene, which isn’t a big issue but I want it to play the sound as the scene changes. I’m new to Godot engine, so thanks for the help!

Add a script to autoload. do it from there

ramazan | 2021-12-25 09:44

:bust_in_silhouette: Reply From: CoolName

Yield is “pausing” code until the requirement is true, in this code - “finished”
So you will have to remove yield so it will be synchronous.
However, idk how it will work when changing scene, but you should try it out yourself