I'm trying to make a loop that prints "aa" when the gui is toggled and when it's not it will print "a" once, but even after I turn off toggle it keeps on going
function aa(toggled) if toggled then repeat wait() print("aa") until not toggled else print("a") return end end
[EDIT] The execution was stuck in a loop at the beginning that it didn't execute the listener event.
Here is the working code:
local button = script.Parent local toggle = true script.Parent.ClickDetector.MouseClick:Connect(function() toggle = not toggle if toggle then aa() end end) function aa() while toggle do print("aa") wait() end print("a") end aa() -- Start the function for the first time
u should probably use a while loop
function aa(toggled) while toggled do wait() end end
try this:
function aa(toggled) repeat print("aa") wait() until toggled == false print("a") end
create a new script and remove the loop in it then hen you want it to be fired disable the first script and enable the other one