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

How to put these mute/unmute scripts into a button?

I recently asked a question how you can mute all sound and I got the answer from RoCopSSS but i'm not sure how I can put them both into a single button

mute

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


unmute

	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

everything I've tried has errored any help?

1 answer

✓ Accepted answer

I recommend using this

local store = {} -- declare it here so both functions can access it
MuteButton.MouseButton1Down:Connect(function()
    for i, object in pairs(workspace:GetDescendants()) do
	if not table.find(store, object) then -- prevents from adding one part 2 times
         if object.ClassName == "Sound" then
             table.insert(store, #store + 1, {['Object'] = object, ['Vol'] = object.Volume})
             object.Volume = 0
         end
      end
  end
end


end)
UnmuteButton.MouseButton1Down:Connect(function()
  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
 store = {} -- clear the table
end)

and I also recommend using this site to help

1 comment

0

how exactly would i make it not just for workspace but all the things like replicated and all them

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