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)
You need to put the local on = false
outside of the OnClicked function, whilst it's inside, you're resetting the value of on
to false every time you click it.
Moving it above line 1 will stop this from happening, and it'll remain constant.