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

How to make a button that can mute boomboxes in a server?

Asked by 2 years ago

My question is the question here (i wrote it on my alt) I just posted here fore answers for it.

0
Im not clicking links theking66hayday 841 — 2y
0
ok sne_123456 439 — 2y
0
Hey! I saw your post again and someone already solved it. Uhmm, can you try my answer too? I tried my best to answer this question, and I’m super sure my answer works the way you wanted. Please don’t abandon my question, please try it, and tell which is better. If the other guy’s script better, then good for him and for you :) T3_MasterGamer 2189 — 2y
0
don’t abandon my answer* T3_MasterGamer 2189 — 2y
0
And don’t qorry I changed mg script to use player.Character like what you said to me T3_MasterGamer 2189 — 2y

2 answers

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

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)
0
the problem is that the sound isnt even in workspace its in the players backpack if they own a gamepass. sne_123456 439 — 2y
0
and i only want to mute boomboxes not all sounds i dont want my background sound gone i already have a separate button for that sne_123456 439 — 2y
0
First, the sound WILL be a descendant of workspace when you equip the boombox. Equipping any tool will be parented to the character, and the character is parented to the workspace. T3_MasterGamer 2189 — 2y
0
And second, I already put a backup line in line 4 incase if you have a background music in workspace. Just remove the two dash lines at the very left of line 4. T3_MasterGamer 2189 — 2y
View all comments (9 more)
0
And use the second script inside the Topbar script T3_MasterGamer 2189 — 2y
0
Getting the boombox from the player’s backpack won’t work since the boombox ur currently hearing is parented in the workspace. T3_MasterGamer 2189 — 2y
0
A sound will only play in workspace, not in the player’s backpack T3_MasterGamer 2189 — 2y
0
Sorry if u think im mad, im not mad im just correcting you :) T3_MasterGamer 2189 — 2y
0
My job is to help scripters T3_MasterGamer 2189 — 2y
0
sure no problem thanks for helping sne_123456 439 — 2y
0
However I want the localplayer's boombox to still produce sound, only should every other player's boombox be muted sne_123456 439 — 2y
0
i would also recommend to not go through the whole workspace and use player.character since i have a lot of stuff in workspace and it would reduce performance sne_123456 439 — 2y
0
Thanks for giving me the idea to use character instead. I updated my answer and it should work now. T3_MasterGamer 2189 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

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)
    })
0
and i know i have unnessessary line i will remove them later! sne_123456 439 — 2y

Answer this question