Basically what I’m trying to point out is if a new sound is made, how do I make it so that new sound’s volume is 0, then even if that sound is still there or removed, once the sfx is unmuted, the sound goes back to its original volume separately.
Script:
local music = game:GetService("SoundService"):WaitForChild("Music")
local volumeworkspace = {}
local volumegui = {}
local clicked = false
function onClicked()
script.Parent["clickfast.wav"]:Play()
clicked = not clicked
if clicked == true then
script.Parent.Text = "Unmute SFX"
script.Parent.BackgroundColor3 = Color3.fromRGB(0,255,0)
for _, obj in pairs(workspace:GetDescendants()) do
if obj and obj:IsA("Sound") then
volumeworkspace[obj] = obj.Volume
obj.Volume = 0
end
end
for _, obj in pairs(game.Players.LocalPlayer.PlayerGui:GetDescendants()) do
if obj and obj:IsA("Sound") then
volumegui[obj] = obj.Volume
obj.Volume = 0
end
end
elseif clicked == false then
script.Parent.Text = "Mute SFX"
script.Parent.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
for _, obj in pairs(workspace:GetDescendants()) do
if obj and obj:IsA("Sound") then
obj.Volume = volumeworkspace[obj]
end
end
for _, obj in pairs(game.Players.LocalPlayer.PlayerGui:GetDescendants()) do
if obj and obj:IsA("Sound") then
obj.Volume = volumegui[obj]
end
end
end
end
script.Parent.MouseButton1Click:Connect(onClicked)