Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Mute ALL sounds in game SoundService, Workspace etc?

Asked by 3 years ago

I've been trying to find a way to script a button that mutes all the sound for only the local player and when they press it again they unmute all sounds and they return to there original volume so basically making all the music's volume 0 and when unmuting the volume it returns back to the original volume.

Is this possible?

A little code I've tried to work with for workspace below.

for i, object in pairs(game.Workspace:GetDescendants()) do
    if object:IsA("Sound") then
        object:Volume
    end
end

1 answer

Log in to vote
0
Answered by 3 years ago

The code must look like

local store = {}
for i, object in pairs(workspace:GetDescendants()) do
    if object.ClassName == "Sound" then
        table.insert(store, #store + 1, {['Object'] = object, ['Vol'] = object.Volume})
        object.Volume = 0 -- change Volume to 0 after storing it in the store table
    end
end

and for the unmute part

for i, v in pairs(store) do -- reads store table
    if v.Object then -- checks if the object still exists
        v.Object.Volume = v.Vol -- sets the object value to the saved volume value
    end
end
Ad

Answer this question