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

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

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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

0
how exactly would i make it not just for workspace but all the things like replicated and all them 5551343214344gfsd -52 — 3y
Ad

Answer this question