Guest User

Untitled

a guest
Sep 30th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.97 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2.  
  3. local Boomboxes = {}
  4. local Status = false
  5.  
  6. -- Fires through ButtonDown
  7. local function MuteBoomboxes()
  8.     for _,TableName in pairs(Boomboxes) do
  9.         local Boombox = workspace:FindFirstChild(TableName):FindFirstChild("BoomBox")
  10.         if Boombox:IsA("Tool") and Boombox.Name == "BoomBox" and Boombox:FindFirstChild("Handle") then
  11.             local Sound = Boombox.Handle.Sound
  12.             if Status == false then
  13.                 warn("Muting boomboxes")
  14.                 Sound.Volume = 0
  15.                 script.Parent.Text = "Unmute Boomboxes"
  16.                 Status = true
  17.             else
  18.                 warn("Unmuting boomboxes")
  19.                 Sound.Volume = 0.4
  20.                 script.Parent.Text = "Mute Boomboxes"
  21.                 Status = false
  22.             end
  23.         end
  24.     end
  25. end
  26.  
  27. -- This function fires when a boombox is added to workspace (equipped) and adds it to the table
  28. workspace.DescendantAdded:Connect(function(Object)
  29.     if Object.Name == "BoomBox" then
  30.         local Character = Object.Parent
  31.         -- Add boombox to the table
  32.         table.insert(Boomboxes, Character.Name)
  33.        
  34.         -- Remove boombox when it is unequipped
  35.         Object.Unequipped:Connect(function()
  36.             print("unequipped")
  37.             Boomboxes[Character.Name] = nil
  38.             print("done")
  39.         end)
  40.     end
  41. end)
  42.  
  43. -- This function fires when the local player left clicks the mute/unmute button
  44. local function ButtonDown()
  45.     -- Fire function
  46.     MuteBoomboxes()
  47. end
  48.  
  49. -- When local player joins, this will find the current boomboxes in the game and add them to the table
  50. for _,Player in pairs(Players:GetPlayers()) do
  51.     local Character = workspace:FindFirstChild(Player.Name)
  52.     if Character and Character:FindFirstChild("Humanoid") then
  53.         local Boombox = Character:FindFirstChild("BoomBox")
  54.         if Boombox then        
  55.             -- Add boombox to the table
  56.             table.insert(Boomboxes, Character.Name)
  57.            
  58.             -- Remove boombox when it is unequipped
  59.             Boombox.Unequipped:Connect(function()
  60.                 print("unequipped")
  61.                 Boomboxes[Character.Name] = nil
  62.                 print("done")
  63.             end)
  64.         end
  65.     end
  66. end
  67.  
  68. script.Parent.MouseButton1Down:Connect(ButtonDown)
Add Comment
Please, Sign In to add comment