Fire a loop/coroutine function without bool and constant checking?

Hello!

I was wondering if there was a way to run a loop without constant checking.

Like for example Loop:Start() and Loop:Pause() or Loop:Play() and Loop:Destroy(), something along those lines.

1 Like

To play a loop, use while true do or while wait() do. To destroy a loop use break. example:

while wait(5) do
local RandomNumber = math.random(1,2) --picks a random number from 1 to 2.
if RandomNumber == 1 then
print("Loop continues")
else
print("Loop is about to stop forever")
break
end
end

However, there’s no way to pause a loop.

1 Like

I was aware of that. I just didn’t know if there was a way to start or break a loop within a variable/function. It’s for multiple commands I’m making. I’ll try to mess with coroutines, see what I can do.

1 Like

Well you’d probably have to set a while loop and next use a “Istance: Bool Value”

Example: Paused = false

If it is in 1 script then you can use another script to change it.

Yeah, that’s how I handle my loops now.

local Connection
local Loop = false

local LoopFunction = coroutine.create(function()
   Loop = true

   Connection = game:GetService("RunService").RenderStepped:Connect(function()
      if Loop == true then
         --
      else
         Connection:Disconnect()
      end
   end)
end)

coolio, I know this was like way back in july but ye