Function never playing sounds

i’ve got a function right here, but when i call it, it prints, but it will just never play the sounds (the sounds are children of the script, they can be played in studio, and everything is set up correctly)

(please note that the room_generated variable (a boolean) is defined elsewhere, and since i’m using task.spawn when i call this function, it works as it should.)

function play_sounds()
	local gen_sfx = script:WaitForChild("generation")
	local gen_finished = script:WaitForChild("finish")

	while not room_generated do
		gen_sfx:Play()
		print(`{gen_sfx} should be playing...`)
		task.wait(0.1)
	end

	gen_sfx:Stop()
	gen_finished:Play()
	print(`{gen_finished} should play right now...`)
end
2 Likes

I don’t remember fully about sound instances, but maybe you have to wait until the sound finished playing and then continue with your loop?

3 Likes

This could be an issue with the sounds not being loaded. Try printing whether or not they are loaded beforehand. You could also try moving them to somewhere link SoundService just in case and set the Playing property to true instead of using :Play().

2 Likes

Try moving the sound instance to the SoundService or the workspace.

1 Like

Hmmm, Well have you checked the ids themselves and tested them. Make sure they are working for you in preview in studio first, secondly check the volume. If all of those functions are good…

Also try putting a space in between each play and stop

gen_sfx: Play()

2 Likes

My bad I’m on mobile ignore the second part your script doesn’t have that error.

1 Like

Instead of Wait for child, because the sound is already there do, gen_sfx = script.generation

See if it makes a differences.