The mod language
A Luau subset. Typed Luau parses: annotations, type/export type, generics and :: casts are accepted and ignored.
Syntax
Supported: local, multiple assignment, compound assignment (+= -= *= /= //= %= ^= ..=), if/elseif/else, while, repeat/until, numeric and generic for (including for k, v in t generalized iteration and __iter), break, continue, functions, closures, varargs, methods (a:b()), string interpolation (`x = {x}`), if-then-else expressions, metatables (__index, __newindex, __call, operators, __tostring, __eq, __lt, __le, __len, __concat, __iter).
Not supported: goto, attributes, type function, nested interpolated strings.
Standard library
print warn error assert pcall xpcall tostring tonumber type typeof select next pairs ipairs unpack rawget rawset rawequal rawlen getmetatable setmetatable require time, plus string (incl. split), table, math (per-mod random), os (time clock date), utf8, bit32, task (wait spawn defer delay cancel), coroutine, Random and a debug.traceback stub. There is no game, workspace, script, Instance, getfenv/setfenv, loadstring or real debug library.
type(handle) is "userdata"; typeof(handle) is its class ("Unit", "Team", ...).
Tasks
main is already a thread. task.spawn(fn, ...) runs fn on a new thread right away, task.defer(fn, ...) on the next frame and task.delay(seconds, fn, ...) after a delay; all three return a thread for task.cancel. task.wait(seconds?) pauses the current thread. Loops that never call task.wait still cannot freeze the server: they are time-sliced (see limits).
task.spawn(function()
while true do
task.wait(5)
print("five seconds passed")
end
end)
local unit = Units.Died:Wait() -- pauses this thread until the next unit dies
Coroutines
coroutine: create resume yield status isyieldable running wrap close. A coroutine is a value of type "thread". It runs nested on the thread that resumes it and shares that thread's step budget, so a coroutine with an endless loop is time-sliced like any other code. task.wait and Signal:Wait() work inside a coroutine (the whole mod thread waits, then the coroutine continues). Limits: 2048 live coroutines per mod, 12 deep when coroutines resume coroutines. Inside hooks and callbacks that must return a value (the damage hook), coroutine.yield between a coroutine and its resumer works, but task.wait is still rejected. Stopping the mod closes every coroutine. A coroutine cannot yield from inside a metamethod or table.sort comparator.
local function range(n)
return coroutine.wrap(function()
for i = 1, n do
coroutine.yield(i)
end
end)
end
for i in range(3) do
print(i)
end
Random
Random.new(seed?) returns a generator (separate state from math.random; the same seed gives the same sequence): :NextNumber(min?, max?), :NextInteger(min, max), :NextUnitVector(), :Shuffle(array) (in place), :Clone().
debug
Only debug.traceback(message?). It returns the message plus the current script:line (no real stack is exposed), so xpcall(f, debug.traceback) works.
Multiple scripts
A mod is a set of named scripts; main runs first and others are loaded with require("name"). A module runs once and its return value is cached.
Interop
Using another mod's modules: a mod can be given an interop id (the box next to the mod name; letters, digits, _ and -, at most 32 characters, empty = shares nothing). While that mod runs, other mods can require("<interopId>:<script>").
- Only scripts whose first non-blank line is
--!exportcan be imported. The editor shows those tabs in green. - The module runs once, inside the providing mod (same VM, same state). The importer gets live proxies: calling a function runs it in the provider (the provider's budget, synchronously), and reading or writing a field touches the provider's real table. Numbers, strings, booleans,
nil,Vector3/CFrame/... and handles (units, teams) cross over; handles are re-wrapped for the importer. - Limits: exported functions cannot yield (
task.waitinside one is an error), and an imported table supports member access and calls but notpairs(),next()or#. - Two running mods cannot share an interop id (the later one fails to start). Importing from a mod that is not running, or from a script without
--!export, is an error. - If the provider stops, everything imported from it errors with "mod '<name>' is no longer running" and stays invalid even if the provider is started again; restart the importing mod too.