local enabled = true
function onClick(clicked)
local backgroundmusic = script.Parent.Parent.Parent:WaitForChild('TopBar'):FindFirstChild('Music')
if enabled == true then
if backgroundmusic then
backgroundmusic.Volume = 0
enabled = false
script.Parent.Text = 'Music: OFF'
else
enabled = false
script.Parent.Text = 'Music: OFF'
while wait(1) do
if script.Parent.Parent.Parent:WaitForChild('TopBar'):FindFirstChild('Music') then
backgroundmusic.Volume = 0
break
end
end
if enabled == false then
if backgroundmusic then
backgroundmusic.Volume = 0.5
enabled = true
script.Parent.Text = "Music: ON"
else
enabled = true
script.Parent.Text = "Music: ON"
while wait(1) do
if backgroundmusic then
backgroundmusic.Volume = 0.5
break
end
end
end
end
end
end
end
script.Parent.MouseButton1Click:connect(onClick)
It works when you click it the first time, but when you try and turn the music back on, it doesn't work. Any ideas why?

1 comment
There is a option to pause music. :Pause(). Also why do you need to break a loop and the function?