Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to stop all other sounds but certain exceptions?

Hey, I have been trying to figure out how to stop all the sounds in the Workspace or at least come up with some way to stop music from playing in my game once a certain sound starts playing. I am not a very experienced scripter as you can tell by my code below but I am attempting to create a script where if it finds a certain sound in my specified folder then it will stop all other songs from playing.

--attempt to stop songs
local attack = game.Lighting.Songs:FindFirstChild("poweron")

if attack then
	--trying to figure out how to find all the other sounds and stop them from playing
	--idk what to put here in order to achieve that
end

1 answer

If all your songs are in a folder / model in the lighting, you can do this to stop all them, then play the song you want


game.Lighting.Songs.poweron.Played:Connect(function()
	--get all the songs from your songs folder and stop them from playing if theyre not the song that is playing
	songs = game.Lighting.Songs:GetChildren()
	
	for i = 1, #songs do
		if(songs[i].Name ~= "poweron")then
			songs[i]:Stop()
		end
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.