#Events
RunService.RenderStepped runs every frame.
local connection;
connection = game:GetService('RunService').RenderStepped:Connect(function(dt)
if (bad) then connection:Disconnect() end;
end);
RunService.Heartbeat runs every frame after the physics simulation completes.
local connection;
connection = game:GetService('RunService').Heartbeat:Connect(function(dt)
if (bad) then connection:Disconnect() end;
end);
RunService.Stepped runs every frame prior to the physics simulation.
local connection;
connection = game:GetService('RunService').Stepped:Connect(function(dt)
if (bad) then connection:Disconnect() end;
end);
Loops
An iterator loop runs for every incremention of x to y via incrementor z.
for i = 0, 1, 0.5 do
...
end
A while loop runs until the given condition is truthy.
while ... do
end
A function loop is bad:
function isbad()
this()
end
function this()
isbad();
end
function this_is_bad()
this_is_bad();
end
A repeat loop runs until the given condition provided after the until keyword is truthy.
repeat
until not bad;
#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.