I’ll go a little more in depth with the title. This script has no problem with muting, but does when I try to unmute it.
script:
local a = game.SoundService.BackgroundMusic
local b = game.SoundService["BackgroundMusic#2"]
local c = game.SoundService["BackgroundMusic#3"]
local d = game.SoundService["BackgroundMusic#4"]
local e = game.SoundService["BackgroundMusic#5"]
local f = game.SoundService["BackgroundMusic#6"]
local button = script.Parent
local MusicPlayer = workspace.MusicPlayer.MusicPlayer
button.Activated:Connect(function()
if a or b or c or d or e or f.Volume == .5 or .2 or 2.2 then
a.Volume = 0
b.Volume = 0
c.Volume = 0
d.Volume = 0
e.Volume = 0
f.Volume = 0
button.Text = "Music: Disabled"
button.BackgroundColor = BrickColor.new("Really red")
else
a.Volume = .5
b.Volume = 0.2
c.Volume = 0.5
d.Volume = 2.2
e.Volume = 0.5
f.Volume = 0.5
button.Text = "Music: Enabled"
button.BackgroundColor = BrickColor.new("Sea green")
end
end)
(I know this script is very sloppy, I haven’t learned tables yet, but when I do, I’ll edit this script.)
This script is for muting and unmuting all of the music in SoundService.
I check the Volume of all the audios in the if statement, and if it is the default value, then I make the Volume to 0.
However, it doesn’t unmute the audio, which is why I made this topic in the first place.
Well here’s the problem, you can’t do that kind of check or f.Volume == .5 or .2 or 2.2 then, you need either or f.Volume == .5 or f.Volume == .2 or f.Volume == 2.2 then or or table.find({0.5, 0.2, 2.2}, f.Volume) then
This does not work, to visualize it the script will read it like so:
a ~= nil or b ~= nil or c ~= nil or d ~= nil or e ~= nil or f.Volume == .5 or .2 ~= nil or 2.2 ~= nil`
Instead I suggest the following
Put all the songs into one dictonary.
Loop through the arrays and check their volume.
mute/set them again.
local SS = game:GetService("SoundService")
local sounds = {
[SS["BackgroundMusic"]] = .5,
[SS["BackgroundMusic#2"]] = .2,
[SS["BackgroundMusic#3"]] = .5,
[SS["BackgroundMusic#4"]] = 2.2,
[SS["BackgroundMusic#5"]] = .5,
[SS["BackgroundMusic#6"]] = .5,
}
Now loop through them:
local isEnabled = true -- music is enabled by default
local debounce = false -- cooldown variable
local function toggleBGSFX(bool)
for sound, maxSound in pairs(sounds) do
sound.Volume = (bool and maxSound) or 0
end
end
button.Activated:Connect(function()
if debounce then return end
debounce = true
toggleBGSFX(not isEnabled)
isEnabled = not isEnabled -- toggle state
task.wait(1) -- cooldown time
debounce = false
end