Hello, My name is OfficerJorden139. I need some help for a project I'm doing. I'm using a loop sequence for my RP stove. But when I click the button that is connected to the script the stove turns on but when I click it again it doesn't remove the loop. Can you please help me?? Here's the code
Plate = script.Parent.Parent.Plate
isOn = false
function on()
isOn = true
while true do
wait(1)
Plate.BrickColor = BrickColor.new("Persimmon")
wait(1)
Plate.BrickColor = BrickColor.new("Terra Cotta")
end
end
function off()
isOn = false
Plate.BrickColor = BrickColor.new("Medium stone grey")
end
function run()
if isOn == false then on() else off() end
end
script.Parent.ClickDetector.MouseClick:connect(run)
Can you please help me?

3 comments
No that didn't work. It's still on a continues loop. Anymore suggestions?
Instead of true in while true do, have while isOn.Value do as that property changes between true and false, and the loop will only continue if the argument is true.
This entire reasoning is incorrect. A globla or global-scope local variable has one state within all nested code blocks.