Server code
Loops
A loop is Luau that keeps running at a tick rate, for a world, a boss or anything that moves by itself. Unlike a plugin, its variables stay between ticks.
local ticks = 0
ansekai.start(function(ctx)
ansekai.log("started at", ctx.rate, "ticks a second")
end)
ansekai.tick(function(ctx, seconds)
ticks += 1
if ticks % 60 == 0 then
ansekai.realtime.set("world/time", os.time())
end
end)
ansekai.stop(function(ctx)
ansekai.realtime.set("world/open", false)
end)| Function | When it runs |
|---|---|
ansekai.tick(fn) | Every tick, seconds is the time since the last one. A loop needs it |
ansekai.start(fn) | Once when the loop starts |
ansekai.stop(fn) | Once when it is stopped, a crash skips it |
ctx.tick counts the ticks before this one, ctx.rate is the tick rate and ctx.loop the name of the loop. Every step is one transaction, see Luau on the server.
Running
A published loop starts and stops from the panel. Publishing a running loop moves it to the new code at once, its old variables go with the old code. A server that falls behind skips ticks instead of catching up.
Plans
| Plan | Loops at once | Ticks a second | Code time of all loops in a second |
|---|---|---|---|
| Solo | 1 | 5 | 50 ms |
| Studio | 5 | 20 | 200 ms |
| Live | 20 | 60 | 1,000 ms |
A game has up to 50 loops, the plan says how many run at once.
Cost
A loop pays for the memory it holds while it runs, $0.00005 for a MB a minute, even when it does nothing. On top come its CPU time, $0.00002 a second, and its ticks, $0.05 a million.
For matches and worlds with players, a room is often the better fit: it hears its players and ends by itself.
Updated November 21, 2026