How to mute multiple sounds using 1 button?

So I’m using ZonePlus for ambient sounds, and as you know this is what it looks like in workspace:
image

My question is, I have a DIFFERENT script that has a toggle mute button (imagebutton found inside a frame), and I want it so that if you click it, it will mute all of the sounds found in the folders even if you enter an area (ZonePlus plays the sound when you enter a specific area), how do I make such thing?

local AmbientFolder = workspace:WaitForChild("AmbientAreas")

for _,v in ipairs(AmbientFolder:GetDescendants()) do
    if (not v:IsA("Sound")) then continue end
        
    v.Volume = 0
end

Alternatively, you could do v:Pause() if you want to preserve whatever volume your sounds have.

I thought that just paused it and kept its current time position, not volume.

you could also do v:Stop() if you wanted the music to restart when it gets played again.

Sense the ZonePlus plays the sound each time you go into an area, also I would recommend changing the name of the Ambient Sound Parts to something like “ZonePlusPart” so this script could work better, so you would have to make a local script in the GUI button like:

local plr = game.Players.LocalPlayer
local HumanoidRoot = plr.Character.HumanoidRootPart --Part to see if it goes into Area part.
local Button = script.Parent -- or where it is located
local AmbientFolder = game:GetService("Workspace"):WaitForChild("AmbientFolder")

local IsMuted = false

Button.MouseButton1Click:Connect(function()
	
	IsMuted = not IsMuted
	
	HumanoidRoot.Touched:Connect(function(hit)
		if IsMuted == true and hit.Name == "ZonePlusPart" then --What you named the part
            wait()
			for _,v in ipairs(AmbientFolder:GetDescendants()) do --@Timelens's script
				if (not v:IsA("Sound")) then continue end

				v.Volume = 0 -- Could be v:Pause() or v:Stop() too
			end 
		end
	end)
end)

That should work!

SoundGroup? Does people not know about this?

2 Likes

You’re creating touched events each time you click that button. That is extremely bad for performance since you aren’t cleaning up the events you create. .Touched is also very bad. You should also be using task.wait rather than wait.

Technically that mutes the sound, but it doesn’t stop it, so that technically answers the question.