Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local Boomboxes = {}
- local Status = false
- -- Fires through ButtonDown
- local function MuteBoomboxes()
- for _,TableName in pairs(Boomboxes) do
- local Boombox = workspace:FindFirstChild(TableName):FindFirstChild("BoomBox")
- if Boombox:IsA("Tool") and Boombox.Name == "BoomBox" and Boombox:FindFirstChild("Handle") then
- local Sound = Boombox.Handle.Sound
- if Status == false then
- warn("Muting boomboxes")
- Sound.Volume = 0
- script.Parent.Text = "Unmute Boomboxes"
- Status = true
- else
- warn("Unmuting boomboxes")
- Sound.Volume = 0.4
- script.Parent.Text = "Mute Boomboxes"
- Status = false
- end
- end
- end
- end
- -- This function fires when a boombox is added to workspace (equipped) and adds it to the table
- workspace.DescendantAdded:Connect(function(Object)
- if Object.Name == "BoomBox" then
- local Character = Object.Parent
- -- Add boombox to the table
- table.insert(Boomboxes, Character.Name)
- -- Remove boombox when it is unequipped
- Object.Unequipped:Connect(function()
- print("unequipped")
- Boomboxes[Character.Name] = nil
- print("done")
- end)
- end
- end)
- -- This function fires when the local player left clicks the mute/unmute button
- local function ButtonDown()
- -- Fire function
- MuteBoomboxes()
- end
- -- When local player joins, this will find the current boomboxes in the game and add them to the table
- for _,Player in pairs(Players:GetPlayers()) do
- local Character = workspace:FindFirstChild(Player.Name)
- if Character and Character:FindFirstChild("Humanoid") then
- local Boombox = Character:FindFirstChild("BoomBox")
- if Boombox then
- -- Add boombox to the table
- table.insert(Boomboxes, Character.Name)
- -- Remove boombox when it is unequipped
- Boombox.Unequipped:Connect(function()
- print("unequipped")
- Boomboxes[Character.Name] = nil
- print("done")
- end)
- end
- end
- end
- script.Parent.MouseButton1Down:Connect(ButtonDown)
Add Comment
Please, Sign In to add comment