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 https://gyazo.com/f49edb2a1b78dca8c0649853edc66f69 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!

Depending on where the Sounds are (Let’s say in a Folder), you could just simply get the children of every Instance that’s a Sound and either:

  • Stop the Sound completely

  • Set the Volume by 0

You can put this through a pairs loop which would iterate (Or loop) through everything that’s inside the Sounds Folder:

local Sounds = workspace.Sounds

for _, Sound in pairs(Sounds:GetChildren()) do
    Sound:Stop()
end
1 Like

could i put that script into a button so like if i press the button it kills all the sound playing instantly?

Depends on what button you’re exactly looking for

If you’re using a ClickDetector, then yes you can do that provided the MouseClick Event

If you’re using a GuiButton, you’d need to use RemoteEvents which would handle client-server transportation so that every sound would stop on the Server Side

You can use GetDescendants() here to get all children, for example:

for _, Sound in pairs(workspace:GetDescendants()) do
    Sound:Stop()
end

Perhaps, but for efficiently purposes you can just simply call GetChildren() for calling unnecessary checks

Also your code would error because there may be the chance that not everything inside the workspace is guaranteed to be a “Sound” Instance, and would not be a valid function for that specific Instance being :Play()

hey idk if im doing it right or not but i did what u said i put the script inside of a part and put clickdetector in it but it wouldnt stop any of the songs? could u maybe make it a model and send it to me so im sure im doing everything right

Could you format your current script that you’re using?

Add 3 of these

`

To format it properly

well I made a part i put a clickdetector and a script inside of it and the script was following : local Sounds = workspace.norwayy

for _, Sound in pairs(Sounds:GetChildren()) do
Sound:Stop()
end

the sound i was using was grouped up and it was called norwayy so i changed it to workspace.norwayy

Ah

So what you’d need to do, is simply reference the ClickDetector’s MouseClick Event as that script isn’t encased inside a function for it to fire when it’s supposed to

You can do something along the lines like this, and it should work fine?

local Sounds = workspace.norwayy
local Part = script.Parent

local function StopAllSounds()
    for _, Sound in pairs(Sounds:GetChildren()) do
        Sound:Stop()
    end
end

Part.ClickDetector.MouseClick:Connect(StopAllSounds)

yeah for some reason it still doesnt work is there a way i can invite you to team create? and you can take a look at it to see if im doing everything right?

You could just send the hierarchy of what your Explorer currently looks like (Preferably the Part’s Descendants), also do check for any possible errors if possible

Okay so here is how it looks like right now u can see the red button that i want to turn of all music with one click https://gyazo.com/79c2745f164663a71d952b1d8e92d492 . Next in this pic u can see whats inside of norwayy you can see it has sound players and signs https://gyazo.com/81ebbd5f3132109b53f433526dd42cc5 . and inside of the sound players is the actual sound and stop and play https://gyazo.com/3b0e981e7b5b10689e6e76cc89adefb9 and lastly its the script and part i made myself to stop all the sound https://gyazo.com/1526942a5e2a84e21dc31c1c2a7af0bf

Ah I see the issue

The script is assuming that there was a Sound instance in the Sounds variable, but it resulte as an error instead

For this situation then, we can call GetDescendants() checking if every Object is a Sound Instance or not:

local Sounds = workspace.norwayy
local Part = script.Parent

local function StopAllSounds()
    for _, Object in pairs(Sounds:GetDescendants()) do
        if Object:IsA("Sound") then
            Object:Stop()
        end
    end
end

Part.ClickDetector.MouseClick:Connect(StopAllSounds)