How end a For Cicle or Repeat cicle

How end One of this two Cicle if the condition becomes true before it comes to the end.

Don’t Comment “Put many checks inside your code with break”

Thank you.

Why not? What do you really want?

In a custom Menu i can’t put inside the script in the Camera Animation 40 Check, also is not optimized I’m sure there are more optimized methods.

Well, you can store your conditions in a dictionary and then test with only one line of the script.

The break method is the only way to stop every kind of loop. repeat and while loops are conditional loops and can be stopped without the use of a break.

while (Condition) do
repeat until (Condition)

While loops will continue to run while the condition is true, and repeat loops will run until the condition is true. For loops require the break method.

Oh Alr And what about the RunService? I have seen it used in some menus

RunService isn’t really a loop (assuming you are referring to .Hearthbeat / .Stepped / .RenderStepped) that just an event, if you wan’t to stop the ‘loop’ your code should look something like this:

local Connection = game:GetService('RunService').Heartbeat:Connect(function()
        -- Do stuff
       Connection:Disconnect()
end)
2 Likes