Events
RunService.RenderStepped runs every frame.
2 | connection = game:GetService( 'RunService' ).RenderStepped:Connect( function (dt) |
3 | if (bad) then connection:Disconnect() end ; |
RunService.Heartbeat runs every frame after the physics simulation completes.
2 | connection = game:GetService( 'RunService' ).Heartbeat:Connect( function (dt) |
3 | if (bad) then connection:Disconnect() end ; |
RunService.Stepped runs every frame prior to the physics simulation.
2 | connection = game:GetService( 'RunService' ).Stepped:Connect( function (dt) |
3 | if (bad) then connection:Disconnect() end ; |
Loops
An iterator loop runs for every incremention of x to y via incrementor z.
A while loop runs until the given condition is truthy.
A function loop is bad:
A repeat loop runs until the given condition provided after the until
keyword is truthy.
Warning and Trivia
Make sure you provide a yielding function for your non-event loops. They will crash your game.
In the script builder community, which is typically centered around CFrame animation, they use a for loop. This is because CFrame:Lerp, the Linear, intERPolation function requires an alpha that signifies the progress between CFrameA and CFrameB, which can easily be given through for i = 0, 1, 0.1 do
as i
would be the given progress.
wait() runs according to the built-in 30hz roblox scheduler. Recommended not to use for quick action.