I made this script in a textbutton, the music play but wont stop playing when i click the button again. I dont get any errors
function OnClicked()
local on = false
if on == false then
script.Parent.Parent.Sound:Play()
on = true
script.Parent.Text = "Stop music"
elseif on == true then
script.Parent.Parent.Sound:Stop()
on = false
script.Parent.Text = "Play music"
end
end
script.Parent.MouseButton1Click:connect(OnClicked)

8 comments
It might be because you made "on" local. Remove Local and then try it.
still not stopping it
This should work if you removed local, I don't see why it wouldn't. Any other scripts screwing with anything?
theres no other scripts in this gui
now its restarting it when i click again
I'd have to check your game or something because the script appears to be fine. Music plays when you click or do you spawn in and it's already playing? This is a local script? If not make it one .
All 'local' does is confine a variable to the scope it was created in. In this script, it's never used outside of the function scope, so the word 'local' is not a problem. Wizzy's answer is correct.
when i click the button the music start playing and when i click it again instead of stopping it does nothing