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
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