Does anyone know how i can turn off all the songs with 1 single command or a button?

So I have a music based game where i have alot of buttons with songs for people to play but here comes the issues some times we get these trollers who join and they spam music meaning they turn on all the songs at once and it just becomes a chaos then it makes me have to go manually turn them off each time Screenshot - f49edb2a1b78dca8c0649853edc66f69 - Gyazo does anyone know how i can implement a script that kills all the sound with 1 click or a command would really be helpful thanks!

1 Like

You can make a table containing all the songs and then as the mouse clicks on the button
you can go through the table(using loops in pairs) and apply the function :Stop() on every one of them
For example:
local songs = {
game.ReplicatedStorage.Believer
game.ReplicatedStorage.Radioactive
}

For i,song in pairs(songs) do
song:Stop()
end

make a table with all songs in it, and use a for loop that will stop the songs

or just put all the songs in one group/folder and use “:GetChildren()”

You can use a SoundGroup Instance to modify the volume of all you scripts at the same time.
All you have to do is place your Sounds in your SoundGroup :

image

And for each sound, select the SoundGroup instance as ‘SoundGroup’ property.

image

Then, if you change the Volume of the SoundGroup, every Sound instance into it will have its Volume changed as well.

image

1 Like

im so lost sorry im like very new to this I have all my sound grouped up in sound players https://gyazo.com/a524e7a06d345b835c56c08ce9e3c5a3?token=820bc35af36a073a025c26d803affefb like this so they can be manually turned off and on but i need 1 button that just turns off all songs instantly

No worries at all, as he said you can use GetChildren() to get all the sounds in your model, and a ‘for’ loop to change them all.

local SoundPlayer = -- your model
local Button = --your button

function StopAllSounds()
	for i, Child in pairs(SoundPlayer:GetChildren()) do
		Child:Stop() -- Use this if you want to stop the sound
		Child.Volume = 0 -- Use this if you just want the sound to be mute
	end
end

Button.MouseButton1Click:Connect(StopAllSounds)

Here’s a function that will stop all your sounds, assuming that every instance inside your model are Sounds.

1 Like
--script under button btw
local SoundService = game:GetService("SoundService")
script.Parent.MouseButton1Click:Connect(function()
    for i, v in pairs(SoundService:GetDescendants()) do
        if v:IsA("Sound") then
            v:Stop()
        end
    end
end)

This will loop through every thing in SoundService and if its a sound it’ll stop it. Not tested.

There’s no condition to check if its a sound or not. Altho it will work you will have unwanted errors in the output, say if there’s a part in there too, it will error and stop saying Stop() is not a valid member of BasePart “Part”

Why does this matter here? What person would put something that isn’t a Sound instance under a SoundGroup?

1 Like

Yes, I specified :

You got a point, it’s always better to check the class of the Child in case the Parent is a model, now if the Parent is a SoundGroup there might not be any child other than Sounds, as @TolkodvadtsatSlov was saying.
But yes, it’s still good to check ! :wink:

1 Like

hey can you check your private messages

Does your game insert “Sound” objects into Workspace so that everyone can hear them?
You can just write a simple script that searches for Sounds in Workspace and deletes them. Something like this:

for _, child in pairs(workspace:GetChildren()) do
if child:IsA(‘Sound’) then
child:Destroy()
end
end

Im not really into how music works so sorry if its a bad solution.