Muting All Players BoomBox Script

Hello, I’ve been recently wondering how I can fix this script gui to allow it to mute all player boomboxes when it comes to ingame.

ATM - it is only muting and unmuting your OWN boombox, which is not what I was trying to do. If anyone can tell me or inform me how to fix my code here to mute ALL player boomboxes then that would be awesome!

Script -

				--[LOCALS]--
local enabledImage = "rbxassetid://6459284138" -- Enabled Image (True) Blue
local disabledImage = "rbxassetid://6459285570" -- Disabled Image (False) Red 
local muted = false -- settings muted to false since they haven't clicked yet

			   --[FUNCTION]--
--Local script inside image button.
--Function that runs when MouseButton1 is clicked.
script.Parent.MouseButton1Click:Connect(function()
	
	-- Playing the sound every click
	script.Parent.Parent.Sound:Play()
	
	-- Grabbing The Sound From BoomBox
	for i,v in pairs(game.Players:GetPlayers()) do
		local tool = v.Character:FindFirstChildOfClass("Tool")
		if tool.Name == "VibeBox" then
			local s = tool.Handle:FindFirstChildOfClass("Sound")
			if muted == false then -- not muted
				if s then
					s.Volume = 0
					muted = true
					script.Parent.Image = disabledImage
				end
			elseif muted == true then -- yes muted
				if s then
					s.Volume = 1
					muted = false
					script.Parent.Image = enabledImage
				end				
			end
		end
	end
	
	
end)


Another problem is that, it will send error’s to the client side if the player is not holding the boombox saying -

If anyone has any idea how to fix please help!

NOTE - The Sound is coming from a boombox, and we are trying to grab the players boombox and then the sound and mute it, which it works just not all players.

It is a LocalScript, which means it will only work for the client.

Thankyou that worked.

@DevCramp

Is this what you’re trying to do?

Make the script mute other boomboxes from the client.

1 Like
				--[LOCALS]--
local enabledImage = "rbxassetid://6459284138" -- Enabled Image (True) Blue
local disabledImage = "rbxassetid://6459285570" -- Disabled Image (False) Red 
local muted = false -- settings muted to false since they haven't clicked yet

			   --[FUNCTION]--
--Local script inside image button.
--Function that runs when MouseButton1 is clicked.
script.Parent.MouseButton1Down:Connect(function()
	
	-- Playing the sound every click
	script.Parent.Parent.Sound:Play()
	
	-- Grabbing The Sound From BoomBox
	for i,v in pairs(game.Players:GetPlayers()) do
        if v ~= game.Players.LocalPlayer then
		local tool = v.Character:FindFirstChildOfClass("Tool")
		if tool.Name == "VibeBox" then
			local s = tool.Handle:FindFirstChildOfClass("Sound")
			if muted == false then -- not muted
				if s then
					s.Volume = 0
					muted = true
					script.Parent.Image = disabledImage
				end
			elseif muted == true then -- yes muted
				if s then
					s.Volume = 1
					muted = false
					script.Parent.Image = enabledImage
				      end				
			      end
		     end
	      end
      end	
end)

@TwinPlayzDev
Use if v ~= game.Players.LocalPlayer then (Checks if it’s not LocalPlayer)

1 Like

There seems to be a few problems with this script. To fix the index nil error, you have to make sure tool exists (isn’t nil) before accessing anything from it like tool.Name.

The other issue could be that the muted variable is being toggled inside of a loop. That means if there are 3 players with boomboxes, it will toggle muted 3 times, resulting in some of the boomboxes not being muted.

Last isn’t really a problem, but you have an elseif statement to check if it is muted, when you already checked if it wasn’t muted in the if statement. You can replace the elseif with an else statement

@TwinPlayzDev_YT

See if any of them work…

Try 1
--[LOCALS]--
local enabledImage = "rbxassetid://6459284138" -- Enabled Image (True) Blue
local disabledImage = "rbxassetid://6459285570" -- Disabled Image (False) Red 
local muted = false -- settings muted to false since they haven't clicked yet

--[FUNCTION]--
--Local script inside image button.
--Function that runs when MouseButton1 is clicked.
script.Parent.MouseButton1Down:Connect(function()

	-- Playing the sound every click
	script.Parent.Parent.Sound:Play()

	-- Grabbing The Sound From BoomBox
	for i,v in pairs(game.Players:GetPlayers()) do
		if v ~= game.Players.LocalPlayer then
			for i2,v2 in pairs(v.Character:GetChildren()) do
		    if v2:isA("Tool") then
			local tool = v2
			if tool.Name == "VibeBox" then
				local s = tool.Handle:FindFirstChildOfClass("Sound")
				if muted == false then -- not muted
					if s then
						s.Volume = 0
						muted = true
						script.Parent.Image = disabledImage
					end
				elseif muted == true then -- yes muted
					if s then
						s.Volume = 1
						muted = false
						script.Parent.Image = enabledImage
							end
						end
					end
				end
			end
		end
	end
end)	

Try 2
--[LOCALS]--
local enabledImage = "rbxassetid://6459284138" -- Enabled Image (True) Blue
local disabledImage = "rbxassetid://6459285570" -- Disabled Image (False) Red 
local muted = false -- settings muted to false since they haven't clicked yet

--[FUNCTION]--
--Local script inside image button.
--Function that runs when MouseButton1 is clicked.
script.Parent.MouseButton1Down:Connect(function()

	-- Playing the sound every click
	script.Parent.Parent.Sound:Play()

	-- Grabbing The Sound From BoomBox
	for i,v in pairs(game.Players:GetPlayers()) do
		if v ~= game.Players.LocalPlayer then
			for i2,v2 in pairs(v.Backpack:GetChildren()) do
		    if v2:isA("Tool") then
			local tool = v2
			if tool.Name == "VibeBox" then
				local s = tool.Handle:FindFirstChildOfClass("Sound")
				if muted == false then -- not muted
					if s then
						s.Volume = 0
						muted = true
						script.Parent.Image = disabledImage
					end
				elseif muted == true then -- yes muted
					if s then
						s.Volume = 1
						muted = false
						script.Parent.Image = enabledImage
							end
						end
					end
				end
			end
		end
	end
end)	
				--[LOCALS]--
local enabledImage = "rbxassetid://6459284138" -- Enabled Image (True) Blue
local disabledImage = "rbxassetid://6459285570" -- Disabled Image (False) Red 
local muted = false -- settings muted to false since they haven't clicked yet

			   --[FUNCTION]--
--Local script inside image button.
--Function that runs when MouseButton1 is clicked.
script.Parent.MouseButton1Click:Connect(function()
	
	-- Playing the sound every click
	script.Parent.Parent.Sound:Play()
	
	-- Grabbing The Sound From BoomBox
	for i,v in pairs(game.Players:GetPlayers()) do
		if v ~= game.Players.LocalPlayer then
			for i2,v2 in pairs(v.Character:GetChildren()) do
				if v2:isA("Tool") then
					local tool = v2
					if tool.Name == "VibeBox" then
						local s = tool.Handle:FindFirstChildOfClass("Sound")
						if muted == false then -- not muted
							if s then
								s.Volume = 0
								muted = true
								script.Parent.Image = disabledImage
							end
						elseif muted == true then -- yes muted
							if s then
								s.Volume = 1
								muted = false
								script.Parent.Image = enabledImage
							end
						end
					end
				end
			end
		end
	end
end)



This seems to work perfectly, and it is muting others.

Also no error for the nil value.

2 Likes

The error for the nil value is gone?

1 Like

Id rather not post a script that fixes everything since you wouldn’t really learn much from copying and pasting a script.
You can check if something is nil or not by using something == nil. The for loop is hard to explain so this and this may be helpful.

1 Like

How would the script look like if it were a button and not an image? So like when you click, the music of others are muted, but when you click again it turns back on. Also, for the text to change like “Mute Boomboxes: ON” and back to “Mute Boomboxes: OFF” kind of thing.

1 Like

There Is actually an easier way to do It, you set the sound to some SoundGroup (Sound.SoundGroup) and If you want to mute boomboxes, just set the SoundGroup Volume to 0. It’s gonna mute every sound that Is connected to that group. :grin:

3 Likes

How exactly does the SoundGroup work? I’m not entirely sure how a SoundGroup is supposed to mute the radio