My question is the question here (i wrote it on my alt) I just posted here fore answers for it.
In the server script in your post, I don't recommend getting the children inside the player, and I also don't recommend using the legacy for i = 1, #childrensTable do
since you can use for i, v in pairs(childrensTable) do
but it still works. Instead, you look for every descendant in workspace and if it's a sound, you can mute it by setting the volume to 0.
local function muteBoom() for _, descendant in pairs(workspace:GetDescendants()) do if descendant:IsA("Sound") then -- if (descendant.Parent.Name ~= "Handle") and (not descendant.Parent.Parent:IsA("Tool")) and (descendant.Parent.Parent.Name ~= "BoomBox") then return end -- only use this if you don't want to mute every sound in the game descendant:SetAttribute("OriginalVolume", descendant.Volume) -- creates a backup descendant.Volume = 0 descendant:GetPropertyChangedSignal("Volume"):Connect(function() -- when the volume changes if descendant.Volume > 0 then -- making sure it isn't muted descendant:SetAttribute("OriginalVolume", descendant.Volume) end end) end end end
But the problem is that this is a VERY BAD practice since it can break the server and anyone can mute everyone's boom boxes, and you also want it to make it happen to the player who clicked (the client). So instead, let's move it to the client.
:bindEvent("selected", function(self) print(("%s was selected!"):format(self.name)) iconz:setLabel("..Unmute Boomboxes..") for _, descendant in pairs(workspace:GetDescendants()) do if descendant:IsA("Sound") then -- if (descendant.Parent.Name ~= "Handle") and (not descendant.Parent.Parent:IsA("Tool")) and (descendant.Parent.Parent.Name ~= "BoomBox") then return end -- only use this if you don't want to mute every sound in the game descendant:SetAttribute("OriginalVolume", descendant.Volume) -- creates a backup descendant.Volume = 0 descendant:GetPropertyChangedSignal("Volume"):Connect(function() -- when the volume changes if descendant.Volume > 0 then -- making sure it isn't muted descendant:SetAttribute("OriginalVolume", descendant.Volume) end end) end end end) :bindEvent("deselected", function(self) print(("%s was deselected!"):format(self.name)) iconz:setLabel(" Mute Boomboxes ") for _, descendant in pairs(workspace:GetDescendants()) do if descendant:IsA("Sound") then -- if (descendant.Parent.Name ~= "Handle") and (not descendant.Parent.Parent:IsA("Tool")) and (descendant.Parent.Parent.Name ~= "BoomBox") then return end -- only use this if you don't want to mute every sound in the game local originalVolume = descendant:GetAttribute("OriginalVolume") -- gets the backup descendant.Volume = originalVolume end end end)
EDIT: Thanks for giving me the idea to use Player.Character
instead. If you want to mute all boomboxes except for you, just go through all players, and if it's not the client (you) it will mute their boombox.
:bindEvent("selected", function(self) print(("%s was selected!"):format(self.name)) iconz:setLabel("..Unmute Boomboxes..") for _, player in pairs(game:GetService("Players"):GetPlayers()) do if player ~= game:GetService("Players").LocalPlayer then local character = player.Character or player.CharacterAdded:Wait() local descendant = character:WaitForChild("BoomBox"):WaitForChild("Handle"):WaitForChild("Sound") or player:WaitForChild("BoomBox"):WaitForChild("Handle"):WaitForChild("Sound") descendant:SetAttribute("OriginalVolume", descendant.Volume) -- creates a backup descendant.Volume = 0 descendant:GetPropertyChangedSignal("Volume"):Connect(function() -- when the volume changes if descendant.Volume > 0 then -- making sure it isn't muted descendant:SetAttribute("OriginalVolume", descendant.Volume) end end) end end end) :bindEvent("deselected", function(self) print(("%s was deselected!"):format(self.name)) iconz:setLabel("..Mute Boomboxes..") for _, player in pairs(game:GetService("Players"):GetPlayers()) do if player ~= game:GetService("Players").LocalPlayer then local character = player.Character or player.CharacterAdded:Wait() local descendant = character:WaitForChild("BoomBox"):WaitForChild("Handle"):WaitForChild("Sound") or player:WaitForChild("BoomBox"):WaitForChild("Handle"):WaitForChild("Sound") local originalVolume = descendant:GetAttribute("OriginalVolume") -- gets the backup descendant.Volume = originalVolume end end end)
Hey there I have also found a sort-of solution: The problem is that it mutes ALL boomboxes even though i want the locaclplayer's boombox to produce sound
so the question is can i remove the localplayer from the table of players?
iconz :setLabel(" Mute Boomboxes ") :setName("boomxes") :bindEvent("selected", function(self) print(("%s was selected!"):format(self.name)) iconz:setLabel("..Unmute Boomboxes..") bool = true bool2 = false while bool do for i,v in pairs(players) do print(v.DisplayName) local backpack = v.Backpack if backpack:FindFirstChild("BoomBox") ~= nil then print("OK") local boombox = backpack:FindFirstChild("BoomBox") boombox.Handle.Sound.Volume = 0 elseif v.Character:FindFirstChild("BoomBox") ~= nil then local boomboxc = v.Character:FindFirstChild("BoomBox") boomboxc.Handle.Sound.Volume = 0 wait() end end end end) :bindEvent("deselected", function(self) print(("%s was deselected!"):format(self.name)) iconz:setLabel(" Mute Boomboxes ") bool = false bool2 = true while bool2 do for i,v in pairs(players) do print(v.DisplayName) local backpack = v.Backpack if backpack:FindFirstChild("BoomBox") ~= nil then print("OK") local boombox = backpack:FindFirstChild("BoomBox") boombox.Handle.Sound.Volume = 1 elseif v.Character:FindFirstChild("BoomBox") ~= nil then local boomboxc = v.Character:FindFirstChild("BoomBox") boomboxc.Handle.Sound.Volume = 1 wait() end end end end) })