Songs not working

I’m trying to make it so when you press the Imagebutton, it turns the off the song but when you press it again it turns on the song. The songs are located inside ScreenGui within a folder, that might be the issue? Let me know if you need more information.

The script:

local part = game.StarterGui.Music.SoundRegions.Part
local part2 = game.StarterGui.Music.SoundRegions.Part2
local part3 = game.StarterGui.Music.SoundRegions.Part3
local part4 = game.StarterGui.Music.SoundRegions.Part4
local part5 = game.StarterGui.Music.SoundRegions.Part5
local part6 = game.StarterGui.Music.SoundRegions.Part6

script.Parent.MouseButton1Click:Connect(function()
	if part.Volume == 0 or part2.Volume == 0 or part3.Volume == 0 or part4.Volume == 0 or part5.Volume == 0 or part6.Volume == 0 then
		part.Volume = 0.5
		part2.Volume = 0.5
		part3.Volume = 0.5
		part4.Volume = 0.5
		part5.Volume = 0.5
		part6.Volume = 0.5
	else
		part.Volume = 0
		part2.Volume = 0
		part3.Volume = 0
		part4.Volume = 0
		part5.Volume = 0
		part6.Volume = 0
	end
end)

Could you provide screenshots of how your ScreenGui is setup?

Here’s the set-up:
Music

i wouldn’t put sounds inside a screengui because you can’t play sounds everywhere. Try to put sounds inside workspace instead.

Wouldn’t that interfere with how the SoundRegions are set-up? And locally.

no i don’t think so, when i made area only music system i just put sound inside the part and played the sounds whenever i touch the part and stop it whenever i stop touching part

and yes it should be on client-side so i put a local script inside StarterCharacterScripts and handled Touched event in this script. If this makes sense.

1 Like

I agree with @AtomTostcuOzgurUsta, you can use this script for your mute and unmute button, assuming that you put the music folder in the workspace.

local musicFolder = workspace.SoundRegions

local muted = false

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

Just put that into a local script parented to the button.
(you can change the music folder variable to wherever you put the folder)

1 Like

You can also do this if you want the music to fade in and out -

local musicFolder = workspace.SoundRegions

local muted = false
local debounce = false

script.Parent.MouseButton1Click:Connect(function()
	if debounce == true then return end
	debounce = true
	
	if muted == false then
		for i, v in pairs(musicFolder:GetChildren()) do
			if v:IsA("Sound") then
				coroutine.resume(coroutine.create(function() -- coroutines so that multiple sounds can tween out at once
					while v.Volume ~= .0 do
						v.Volume -= .1
						wait(.1)
					end
				end))
			end
		end
		muted = true
	else
		for i, v in pairs(musicFolder:GetChildren()) do
			if v:IsA("Sound") then
				coroutine.resume(coroutine.create(function()
					while v.Volume ~= .5 do
						v.Volume += .1
						wait(.1)
					end					
				end))
			end
		end
		muted = false
	end
	
	debounce = false
end)
1 Like

Yeah I already have that set-up in another script, thanks though. Also, another problem I encountered after I supposedly fixed it is that once the song loops for a second time and you’ve muted it the first time. it’ll start playing again.

Updated script:

local part = game.Workspace.SoundRegions2.Part
local part2 = game.Workspace.SoundRegions2.Part2
local part3 = game.Workspace.SoundRegions2.Part3
local part4 = game.Workspace.SoundRegions2.Part4
local part5 = game.Workspace.SoundRegions2.Part5
local part6 = game.Workspace.SoundRegions2.Part6

script.Parent.MouseButton1Click:Connect(function()
	if part.Volume == 0 or part2.Volume == 0 or part3.Volume == 0 or part4.Volume == 0 or part5.Volume == 0 or part6.Volume == 0 then
		part.Volume = 0.5
		part2.Volume = 0.5
		part3.Volume = 0.5
		part4.Volume = 0.5
		part5.Volume = 0.5
		part6.Volume = 0.5
	else
		part.Volume = 0
		part2.Volume = 0
		part3.Volume = 0
		part4.Volume = 0
		part5.Volume = 0
		part6.Volume = 0
	end
end)