Hi,
I am trying to get this script (which I made a long while ago) to stop and start music, which it half does. When I press to turn off, the music stops, but then after a while music continues again?
Anyone know how to stop the music altogether?
local Clicked = false function onClick() Clicked = not Clicked script.Parent.BrickColor = BrickColor.new("Really red") -- Same here while Clicked do script.Parent.Parent.Sound1:Play() wait(120) script.Parent.Parent.Sound1:Stop() wait(.1) script.Parent.Parent.Sound2:Play() wait(120) script.Parent.Parent.Sound2:Stop() wait(.1) script.Parent.Parent.Sound3:Play() wait(120) script.Parent.Parent.Sound3:Stop() wait(.1) script.Parent.Parent.Sound4:Play() wait(120) script.Parent.Parent.Sound4:Stop() wait(.1) script.Parent.Parent.Sound5:Play() wait(120) script.Parent.Parent.Sound5:Stop() wait(.1) script.Parent.Parent.Sound6:Play() wait(120) script.Parent.Parent.Sound6:Stop() wait(.1) script.Parent.Parent.Sound7:Play() wait(80) script.Parent.Parent.Sound7:Stop() wait(.1) end if not Clicked then script.Parent.BrickColor = BrickColor.new("Medium stone grey") script.Parent.Parent.Sound1:Stop() script.Parent.Parent.Sound2:Stop() script.Parent.Parent.Sound3:Stop() script.Parent.Parent.Sound4:Stop() script.Parent.Parent.Sound5:Stop() script.Parent.Parent.Sound6:Stop() script.Parent.Parent.Sound7:Stop() end end script.Parent.ClickDetector.MouseClick:connect(onClick)
Basically, you can just check after each song if the Clicked value is still true. You can do this by adding an if statement to check the value.
while Clicked do if Clicked then script.Parent.Parent.Sound1:Play() wait(120) script.Parent.Parent.Sound1:Stop() wait(.1) if Clicked then -- repeat the code for each song end end end
This is a very simple way, but it works.