I am a total programming noob so this might be an easy fix but I’ve been trying to make a button that mutes and unmutes the music playlist I have going in my game.
I have this script that runs the playlist so I’ve been trying to find a way where I can make the mute button I have just turn on or off the script entirely.
If there’s a better way to accomplish this please let me know, and any advice would be greatly appreciated!
Just loop through the music and turn their volume to 0, and then set it back after. This is the best as it won’t affect your other systems, while being way easier to implement.
Try this:
--//Variables
local SoundFolder = workspace.Sound
local Button = script.Parent --//Reference your button
--//Controls
local isMuted = false
--//Tables
local VolumeCache = {}
--//Functions
Button.MouseButton1Click:Connect(function()
isMuted = not isMuted
if isMuted then
for i, sound in ipairs(SoundFolder:GetChildren()) do
VolumeCache[sound] = sound.Volume
sound.Volume = 0
end
else
for i, sound in ipairs(SoundFolder:GetChildren()) do
sound.Volume = VolumeCache[sound]
end
end
end)