Namespaces accept both . and : calls (Units.Spawn(...) or Units:Spawn(...)). Handles use : for methods. Reading or writing a member a handle does not have is an error.
Every event in the API (Game.MatchStarted, Units.Died, a button's Clicked, ...) is a Signal:
Member
Description
signal:Connect(fn) -> Connection
Call fn(...) each time the signal fires. At most 4096 connections per signal.
signal:Once(fn) -> Connection
Like Connect, but disconnects itself after the first call.
signal:Wait() -> ...
Pause this thread until the next fire and return its arguments. Not allowed inside hooks or exported interop functions.
connection.Connected
false once disconnected (or after a Once has fired).
connection:Disconnect()
Stop receiving calls. Calling it again does nothing.
Each handler runs on its own thread, so it may task.wait. Handlers start right away while the mod's per-frame event budget (50k steps) lasts; after that they start on the next frame.
Hooks let a mod change or veto what the game is doing while the game waits for the answer. Set one with Game.SetHook(name, fn). Calling it again replaces the hook, and fn = nil removes it.
Hook
Called as
Return
"Damage"
fn(target, source?, amount) for a damage event (see the exceptions below). target is a Unit or Building; source is the attacking Unit/Building, or nil when there is none (missile hits).
A number in 0 <= n < 1e9 replaces amount. nil or anything else (negative, NaN, a string, ...) keeps amount.
"CanBuild"
fn(player, team, buildingType, position) when a player places a building. position is the ground point (Vector3).
false refuses. false, reason also shows the player reason. Anything else allows.
"CanRecruit"
fn(player, team, building, unitType) when a player queues a unit at building.
Same as CanBuild.
Rules for every hook:
No yielding.task.wait, Signal:Wait() and so on make the call fail. A hook gets 50k steps per call.
Failure means no opinion. A hook that errors, yields or overruns allows the action, and a Damage hook leaves amount unchanged.
Shared budget. All hook calls from all mods share 6 ms and 2000 calls per frame. Past that, hooks are skipped for the rest of the frame (actions allowed, damage unchanged), and a warning is logged at most once every 5 seconds.
Several mods. Hooks run in the order the mods started. Damage hooks chain: each one gets the previous hook's result as amount. For CanBuild/CanRecruit, the first false refuses and later mods are not asked.
Gate hooks run after the game's own cheap checks (money, placement, ...) and before money is taken.
Refusal reasons (a string of up to 200 characters) are filtered as the mod owner's text. The first time a particular reason is used, the player sees the game's "blocked by a mod" message and gets the reason as a toast once filtering finishes. After that, the reason is shown directly.
Damage details:
amount is the base damage, before the game applies the attacker-versus-target multipliers and the target's Vulnerability. Returning amount * 0.5 halves the final damage.
The hook is not called for damage dealt by mods (:Damage(), writing Health), function zones (func_damage), or damage over time from status effects (Missile_CorroderEffect, Missile_BlightEffect, Bleeding).
The hook is also not called when the target is not a unit or building (a projectile hitting a missile).
Projectile hits call it once per target hit: the direct hit, then each splash target with amount already reduced for splash. A unit carried inside a hit transport gets its own call, with half of the transport's final damage as amount.
Queue a unit like the recruit button: costs money and needs the research unless Free. Ignores CanRecruit, since the mod sets the rules. 100/s, sharing the 1000-unit global queue.
A server holds more players than a match has teams (24 slots, at most 6 teams, one player per team; matches are joined through the lobby place), so the rest spectate. During a match a player without a team is a spectator; between matches nobody has a team.
During a match, put the player on a team nobody plays (they take it over as it is, like joining mid-match, and their camera moves to its base), or make them a spectator (their team keeps going without a player). Errors when the team already has a player or no match is running.
Blocks exist only during a match. With Collide = true (default) units collide with the block (static TinyPhase body) and path around it (flow-field obstacle).
The match's zones, optionally of one type (e.g. "func_capture"). At most 1000.
Zones.Create(type, { Position = Vector3 | CFrame = CFrame, Size = Vector3, Data = { ... }? }) -> Zone
Make a zone owned by the mod, during a match only. Data holds the type's settings as in a map (ZoneCatalog); unknown keys and bad values are errors.
Zones.GetCreatableTypes() -> {string}
The types Create accepts: func_capture func_damage func_heal func_hill func_income func_status func_trigger. Map layout types and the spawning types are not creatable: use Units.Spawn.
Zones.Captured(zone, fromFaction, toFaction)
Signal. A faction is an alliance or team name; "" = neutral.
A created zone's label is filtered as the owner's text and shows the default name until the filter answers; a capture zone's owner must be a team or alliance in the match. Limits: 100 live zones per mod, 20 created per second, sides up to 4000 studs. Zones end with the match and are removed when the mod stops.
A small persistent key/value store per owner and mod name (DataStore TSR_ModStorage_v1; renaming a mod starts a new, empty store).
Member
Description
Storage.Get(key)
A fresh copy of the stored value, or nil.
Storage.Set(key, value)
Store a value; nil deletes.
Storage.Delete(key)
Remove a key.
Storage.Increment(key, delta = 1) -> number
Add to a number and return the result. A missing key counts as 0; a key holding something else is an error.
Storage.Keys() -> {string}
Every key, sorted.
Storage.Flush()
Save now.
Keys are letters, digits, _ - . (at most 64 characters).
Values are strings, finite numbers, booleans and plain tables (an array or a string-keyed map, at most 10 deep; no functions, handles, Vector3 etc.).
Limits: 500 keys, 64 KB per value, 1 MB per store, 100 writes/s.
Reads and writes use memory and never yield; the store is saved every 30 seconds, on Flush() and when the mod stops. If the DataStore is unavailable (for example Studio without API access) the mod is warned and the store lasts only until it stops.
Panels on players' screens, built from a fixed set of widgets. The server builds and validates the tree, filters every piece of text, and sends clients only safe values, so a mod never runs code on clients.
local panel = UI.Create("Panel", { Title = "Scores", Anchor = "TopRight" }) -- third argument: players (nil = everyone)local timer = panel:Add("Text", { Text = UI.Format("Wave {1} - {2:time} left", wave, seconds) })
local skip = panel:Add("Button", { Text = "Vote skip", Style = "Danger" })
skip.Clicked:Connect(function(player) print(player.Name, "voted to skip") end)
local box = panel:Add("TextBox", { Placeholder = "Team name", MaxLength = 40 })
box.Submitted:Connect(function(player, text) print(text.Raw); timer.Text = text end)
A top-level panel (kind must be "Panel"). players: nil or "Everyone", "Spectators", "Participants", a Team (its player), a Player, or an array of Players. The named groups and Teams are re-checked continuously, so a panel follows players joining, leaving and switching teams.
UI.Format(template, ...) -> FormattedText
Text with slots {1}..{16} (template up to 500 characters). Styles: {1:int} (rounded), {1:time} (m:ss or h:mm:ss), {1:pct} (0.5 -> 50%). Slot values: numbers, Player (display name), Team (name), PlayerText. Not plain strings: put fixed text in the template. FormattedText.Template reads the template back.
The widget it was added to, or nil for a top-level panel.
widget:Add(kind, props?) -> Widget
Add a child widget (Panel and Row only).
widget:Set(props)
Set several properties at once.
widget:GetChildren() -> {Widget}
Its child widgets.
widget:Clear()
Destroy its children.
widget:Destroy()
Destroy the widget and its children.
widget:SetAudience(players?)
Top-level panels only: change who sees it (same players as UI.Create).
The properties of each kind below are read/write fields of the widget. Setting a property on a destroyed widget does nothing. Unknown properties and wrong types are errors.
Visible (true), Order (0, -1000..1000; lower first)
Panel
Title (""), Anchor ("TopRight"; top level only: TopLeft Top TopRight Left Center Right BottomLeft Bottom BottomRight), Width (240, 120..600; top level only)
Row
children side by side, sharing the width
Text
Text (""), Color ("Text"), Size ("Body": Caption Body Title), Align ("Left": Left Center Right)
Button
Text (""), Style ("Default": Default Primary Danger Success), Disabled (false)
Clicked(player)
ProgressBar
Progress (0; clamped to 0..1), Label (""), Color ("Accent")
Colours are a Color3 or a theme colour name, which follows the player's UI theme: Text TextMuted Accent Gold Danger Success Positive Negative MoneyGreen PowerYellow LabsBlueText QueueOrange HealthRed.
Text properties (Text, Title, Label, Placeholder) accept:
a string: filtered as the owner's text. Results are cached, so setting the same string again is free, but every new string is a filter call (25 per second per mod, burst 75; over that, setting it errors). Text appears once the filter answers; until then the widget keeps its previous text. If filtering fails the widget shows nothing.
UI.Format(...): only the template is filtered (once, then cached), so timers and scores that change every second cost nothing. Use this for anything that changes.
What a text box's Submitted gives you. Submissions are dropped if they are blank, longer than MaxLength, or fail filtering.
Member
Description
playerText.Raw
Exactly what the player typed, after trimming. Use it for commands and parsing; never assume it is safe to show.
playerText.Text
Filtered as the typing player's broadcast text. tostring(playerText) is Text.
playerText.Player
Who typed it.
Panels stack inside their anchor region (by Order), scale with the HUD, sit above the HUD and below menus, show a "MOD" badge, and are hidden for players who turned off Settings > Show Mod Panels. Buttons and text boxes only react for players who can see them; the server checks the widget, its visibility and the audience on every event. Everything the mod created is removed when it stops.