Change The Volume Of A Folder Of Audios

Hello, I have a folder of sounds and I want to change the volume of all of them in a script. I already have a mute button and here is my script so far. :arrow_down: It only changes the volume of the song that is currently playing.

local Songs = game.Workspace.Sounds

script.Parent.MouseButton1Click:Connect(function()
	for _, Song in pairs(Songs:GetChildren()) do
		if Song:IsA("Sound") then 
			if Song.IsPlaying == true and Song.Volume == 0.5 then
				Song.Volume = 0
				script.Parent.Image = "rbxassetid://6664391914"
			else
				if Song.Volume == 0 then
					Song.Volume = 0.5
					script.Parent.Image = "rbxassetid://6664390892"
				end
			end
		end
	end
end)

:sweat_smile:

I believe Roblox is just doing what you’re telling it to, you’re checking if the track is currently playing, in order to achieve what you wanted to simply change it to:

if Song.Volume == 0.5 then
1 Like

@Afrxzo perfectly described the issue you’re going through, that simple fix should be enough, but a simpler way to do your mute system would be using the Tenery operator and using a varaibel to check if you mute the sound or not, something like this

local Songs = game.Workspace.Sounds

local mute = false

script.Parent.MouseButton1Click:Connect(function()
	for _, Song in pairs(Songs:GetChildren()) do
		if Song:IsA("Sound") then 
			Song.Volume = mute and 0.5 or 0
		end
	end
	script.Parent.Image = mute and "rbxassetid://6664390892" or "rbxassetid://6664391914"
	mute = not mute
end)

You also don’t really need the script.Parent.Image line to be in the loop, you just need it to be outside of it

2 Likes