Mute music button

hi i just need help with my mute music script because its not working.

this is my current button script and music script

my knowledge on scripting is not so great


music
script

1 Like

The default volume of a Sound is 0.5, can you confirm the volume of the sound you have? Probably better to use a bool value for this anyways as you may want to adjust volume in the future.

local music = game.Workspace.Music
local muted = false


script.Parent.MouseButton1Click:Connect(function()
	if muted == false then
		music.Volume = 0
		muted = true
	else
		music.Volume = 1
		muted = false
		
	end
end)
1 Like

Oh, wait, sorry, is there a Sound in workspace called Music? Looking at your explorer it doesn’t look like it, yet you’ve defined music as game.Workspace.Music. Anyways, using the actual Sounds folder you have, this script should set you on the right track. Keep in mind this is simply setting the value from 0 to 1 and vice versa and doesn’t respect previously inputted volume. If you wanted to do so, I’d recommend making storing all of the previous volumes somewhere.

local MusicHolder = workspace.Sounds
local muted = false

script.Parent.MouseButton1Click:Connect(function()
		if muted == false then
		for _, v in pairs(MusicHolder:GetChildren()) do
			if v:IsA("Sound") then
				v.Volume = 0
			end	
		end
		muted = true 
	else
		for _, v in pairs(MusicHolder:GetChildren()) do
			if v:IsA("Sound") then
				v.Volume = 1
			end	
		end
		muted = false 
	end
end)

4 Likes