Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Mute ALL sounds in game SoundService, Workspace etc?

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

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.