Systems
What a system is, its
system script, the three kinds of script, and how sides, types and interfaces fit in.
system script, export Reason; a server one by its RunContextuse Wallet, then Wallet.Start()Wallet.ReasonWhat a system is
A system is one
system script plus every Shot Script whose system line names it, wherever those scripts sit in the tree. The system's name is its system script's name. The system script is the system's public face, the one script the rest of the game uses. Everything else in the system is its inside.
The system line decides which system a script is in. The folder never does. Every Shot Script starts with one:
system script | this script is the |
system script. | the script's parent is the |
system script. | the |
system game. | a full path from game |
- One system line per script, the
system script too: it says system script. A script that is a system of its own sayssystem scriptas well. - The path starts with
scriptorgame. Only--!lines, comments and blank lines stand above the line, and it makes no Luau. - A script joins a system only through its own system line. Where it sits never joins it.
- A bare name, as in
system Wallet, is an error whose words write the path: a system line always takes a path. - A Shot Script with no system line is an error, and its words name the line to write.
- Renaming or moving a
system script rewrites every member's system line, and moving a member rewrites its own. - Mark as ShotScript in ShotScript Editor writes a system line only on a ModuleScript: under a
system script it writes system script.Parent, which joins that system; a script on its own getssystem script. A Script or LocalScript never gets one. - A standalone types system is one script that says
system script, exports its types and returns nothing: other scripts import them (INTERFACES ANYWHERE IN A SYSTEM has one). - A Boot Script takes no system line and belongs to no system (BOOT SCRIPTS).
- A system may sit inside another one. The inner one counts as outside the outer one: position in the tree doesn't matter.
The example
A small game with two systems: Wallet keeps every player's coins on the server, and Shop sells things for coins.
ServerScriptService
Init a Folder
Server a Script with RunContext Server: starts the game (BOOT SCRIPTS)
Wallet the system script of Wallet, a ModuleScript with RunContext Server
Purse interface Payer, class Receipt and class Purse (MANY ITEMS IN ONE SCRIPT)
Shop the system script of Shop, a ModuleScript with RunContext Serversystem script
use script.Purse
export Reason
export Payer
«Why a player's coins changed»
system type Reason = "Pickup" | "Shop"
local Players = game:GetService("Players")
«Every player's purse, kept on the server.»
module Wallet = {
public Purses : {[Player] : Purse} = {}
function Start()
Players.PlayerAdded:Connect(function(player : Player)
module.Purses[player] = Purse.Empty()
end)
end
function Find(player : Player) : Payer?
return module.Purses[player]
end
function Give(player : Player, amount : number, reason : Reason)
local purse = module.Purses[player]
if purse then
purse:Add(amount, reason)
end
end
}
return Walletsystem script.Parent
interface Payer = {
CanPay(amount : number) : boolean
}
class Receipt = {
public Amount : number
public Reason : Reason
constructor new(amount : number, reason : Reason)
local self : Receipt = init()
self.Amount = amount
self.Reason = reason
return self
end
}
class Purse implements Payer = {
public Coins : number
internal Receipts : {Receipt}
constructor new(coins : number)
local self : Purse = init()
self.Coins = coins
self.Receipts = {}
return self
end
public Add(amount : number, reason : Reason)
self.Coins += amount
table.insert(self.Receipts, Receipt.new(amount, reason))
end
public CanPay(amount : number) : boolean
return self.Coins >= amount
end
public static Empty() : Purse
return Purse.new(0)
end
}
return Pursesystem script
use Wallet
«A price in coins»
system type Price = number
system type Sale = { Price : Price, Why : Wallet.Reason }
module Shop = {
function Buy(player : Player, sale : Sale) : boolean
local payer = Wallet.Find(player)
if payer == nil or not payer:CanPay(sale.Price) then
return false
end
Wallet.Give(player, -sale.Price, sale.Why)
return true
end
}
return ShopInit/Server.shot (a Script with RunContext Server)
use Wallet
use Shop
Wallet.Start()- Wallet is one system of two scripts: its
system script and Purse. Purse joins it through its own system line, system script.Parent, not because it sits under Wallet. return Walletat the bottom says what the script hands out: the module Wallet. In the
system script that is the system's API. Purse's script hands out the class Purse the same way.export Reasonandexport Payerhand those types out. Shop writesWallet.Reason, and since Shop uses Wallet, a bareReasonworks there too.- Shop reaches Wallet only through its
system script: use Walletfinds the nearest script named Wallet. Purse is Wallet's inside, so Shop never uses it. - Sale appears in Buy's signature, so it is a
system type, and so is Price, which Sale names. A plaintypeline is its file's own and can't appear in a module's member signatures or a system type (THE SYSTEM'S TYPES). - The side of each system is its ModuleScript's RunContext, never a word on the system line (SIDES).
- Init/Server is a Boot Script: it belongs to no system and calls Wallet's Start (BOOT SCRIPTS, and Scripts).
The
system script
Exactly one script of a system is its
system script: the one whose system line says system script. Its return at the bottom is the system's API, what the system hands out:
module Wallet = { ... }, then return Wallet | a module: the usual |
class X = { ... }, then return X | a class |
local Settings : T = v, then return Settings | a value of type T |
use script. | hands out a child script; outside, it is Cursor |
no return | a blank system: it hands out only its exported types |
A module per side, module X { server { ... } client { ... } }, goes out the same way, with return X.
- A
system script that returns nothing is a blank system (THE KINDS OF SCRIPT). It hands out no value, only the types it exports. - A system line takes no side word. The side is the ModuleScript's RunContext property, set in ShotScript Editor's Properties.
- A script has one system line, and a system has one
system script.
A system that hands out a child script:
system script
use script.CursorState
system type CursorMode = "Free" | "Center"
return CursorStatesystem script.Parent
client module CursorState = {
public Mode : CursorMode = "Free"
}
return CursorStateOutside the system it is Cursor (use Cursor, then Cursor.Mode); the script keeps its own name, CursorState. Cursor's RunContext is Client, since shared code can't use a
client module (SIDES). Moving CursorState rewrites its own system line.
A child class goes out the same way:
system script
use script.Pulse
export Pulse
return Pulsesystem script.Parent
class Pulse = {
public Rate : number
constructor new(rate : number)
local self : Pulse = init()
self.Rate = rate
return self
end
}
return PulseWhat the rest of the game sees
Code outside a system reaches only its
system script, and through it only what it hands out and exports. Shop uses Wallet (use Wallet, the nearest one, or a full path from game), never Wallet's Purse.
- A bare
use Walletwhere neither the script's folder nor any folder above it holds Wallet is an error that says where Wallet is and the fulluseto write, such asuse game.. Its fix writes it, and the error goes.ReplicatedStorage. Systems. Wallet - Reaching into another system's member is an error, and allow is the one way in (ALLOW). The error never stops the script compiling.
- In a ShotScript script, a direct
require(...)of another system's member is the same error. When the system exports that member, its fix writesuse <System>. A Luau script stays plain Luau. - When that
require(...)crosses sides, between server and client code, its row has nousefix: auseacross sides is an error too (SIDES). - A
require(...)of a member its system hands out as a value, aspublic Purse = Pursein Wallet's module, gets a row that says to reach Purse through what Wallet hands out. Its fix writesuse Walletand readsWallet.Pursein place of the require, and the row goes. export Namein the
system script hands a system type out: outside it is Wallet.Name, or bare through ause. The type of what the system script returns goes out by itself.- A row on a system type the
system script doesn't export names the line to write and where: add export Name to the system script's path. - An export line takes one name:
export TimerLook, SplitLookis an error whose fix writes one export line per name. - An export may also name a class that a use line of the system reaches, even one whose script is in another system: its X goes out, never its XClass. An export that names neither is an error.
export system type A = Bin the
system script is exactly system type A = Bplusexport A, so one line re-exports a member system's type:export system type SomeProperty = BaseLighting..SomeProperty export system set S = ...is exactlysystem set S = ...plusexport S.- A public signature that uses a type the
system script doesn't export gets no row. - Starting a blank inside another system is allowed: a blank hands out no value.
- A system nested inside another counts as outside it.
- A
useof a standalone types system runs nothing and brings in its exported types, as a blank's use does. - Who uses whom across a place:
shot wiring, orshot refsfor one system (The shot command).
Allow
A member script may let another system in. allow Till in Ledger's header lets every script of the system Till reach Ledger directly: its public values and types, never its file-local items. Two systems can then share one leaf without a require loop.
system script
use script.Ledger
module Bank = {
public Total : number = Ledger.Sum
}
return Banksystem script.Parent
allow Till
module Ledger = {
public Sum : number = 0
}
return Ledgersystem script
use script.Parent.Bank.Ledger
module Till = {
public Seen : number = Ledger.Sum
}
return Till- An allow line goes in the header, at column 1, one system per line.
export Namein such a member hands its types to the systems it allows. For now only ShotScript Editor reads it.- An allow that does nothing,
allow A, Bon one line, one below the item, and one naming no system each get a row. - An allow naming a script that is in no system, such as a Boot Script, gets a row that says so and shows the way through: reach the member through its
system script.
The kinds of script
Every .shot file is a script of one of three kinds:
Shot Script | a ModuleScript of items (classes, modules, interfaces, values): it hands out what its return says |
System Script | the Shot Script whose system line says system script: the system's public face (THE SYSTEM SCRIPT) |
Boot Script | a Script that runs on its own, on the server or a client, and returns nothing (BOOT SCRIPTS) |
A blank is a Shot Script with no return at the bottom: plain Luau that hands out nothing. Its side is its RunContext property (Client or Server; with none, it is shared).
- Every Shot Script starts with its system line, a blank too.
start Blankruns it.import X from Blankbrings in its types and runs nothing.use Blankruns it and brings in its exported types too.- A start of anything that hands out a value is an error ("use it").
- Any system may start a blank inside another system. A blank that yields stalls whoever starts it.
Sides
Every script is shared, server or client code. Server code uses shared and server code, client code uses shared and client code, and shared code uses shared code only. A use or require across is an error at its line.
A ModuleScript's side is its RunContext property, never a word on the system line. Wallet's is Server, so Shop, server code, uses it freely, while use Wallet in a
client Boot Script is an error. The page Server and client has the side rules, side blocks, side extensions, a value per side and a module per side.
The system's Types
Types files are gone: their type lines live in the
system script as system type and system layout lines (Layouts and sets), with their docs. Every system type belongs to the whole system and is bare in each member. Types has the whole story; here is how it fits a system.
system type X = ...in any member registers X for the whole system: every script of the system sees it. A system holds one system type of each name.system setregisters a set the same way (Layouts and sets).- A plain
type X = ...in a script is that file's own. It can't appear in anything that registers, such as a class's or module's member signatures or a system type. - Each item's type belongs to its system too: class X gives
XandXClass, module X givesXModule. - Rows, hover, signature help and completion name a module, class or object by the name you wrote, such as TimedSale, Scheduler or Lighting, never by its made Luau name (TimedSaleModule, SchedulerClass, LightingModule).
- Imports bring in types only, never a value:
import A, B from <path>,import * from <path>, or by a bare name, as inimport WorldId from WorldInfos(the nearest WorldInfos). They go in any script of the system, and every script of it then sees the names. To call something, use it. - When two systems use each other only for types, the row on the
useline offers the import as its fix (import X from <path>, which loads nothing), as a require loop's row does. When values are read too, it offers no fix.
A member of the ValueCollector system, cut down to its fields and its constructor:
system script.Parent
import QuickSignal from game.ReplicatedStorage.Globals.QuickSignal
use ValueCollectorItem
use QuickSignal
system type ValueCollectorMode = "Add" | "Multiply" | "MultiplyToOne"
────────────────────────────────────────────────────────────────────────────────────────────────────────────
class ValueCollector = {
public Mode : ValueCollectorMode
public Changed : QuickSignal
internal _items : {[string] : ValueCollectorItem}
internal _baseValue : number
internal _shouldRecalc : boolean
internal _cachedValue : number
internal _firedValue : number
internal _deferQueued : boolean
────────────────────────────────────────────────────────────────────────────────────────────────────────────
constructor new(mode : ValueCollectorMode)
local self : ValueCollector = init()
self.Mode = mode
self.Changed = QuickSignal.new()
self._items = {}
self._baseValue = if mode == "Multiply" then 1 else 0
self._cachedValue = self._baseValue
self._firedValue = self._baseValue
self._shouldRecalc = false
self._deferQueued = false
return self
end
}
return ValueCollector- The import brings in only the type QuickSignal.
use QuickSignalrequires the script, so the constructor can callQuickSignal.new(). - ValueCollectorMode appears in the class's members and its constructor's signature, so it is a
system type.
A use of system X in any script of system S brings X's exported types into S, bare in every script of S, with no extra require. BaseLighting's
system script has export LightingMode, so after use BaseLighting the type LightingMode is bare here:
system script.Parent.Parent
use BaseLighting
class SunLightingMode = {
public LightingMode : LightingMode
public UseWhiteBackground : boolean
constructor new(config : LightingModeConfig)
local self : SunLightingMode = init()
self.LightingMode = BaseLighting.LightingMode.new(config)
self.UseWhiteBackground = config:GetAttribute("UseWhiteBackground") or false
return self
end
}
return SunLightingModeLightingModeConfig is a layout another member of the same system declares (Layouts and sets).
- Two systems bringing one name into S is an error: write
X.Name, or import the one meant. - An outside type used in a member's signature, a system type or an
extendsneeds an import in some script of the system. - A system is Global when its
system script's Global property, in ShotScript Editor's Properties, is set to true. A Global's values and exported types are bare in every script, with no useand noimport. A folder named Globals is only a convention: only the Global property makes a system Global, and the oldGlobalattribute no longer does. - A Boot Script's types: a
usebrings that system's exported types in bare, and every Global's. Its own types are plaintypelines. - A script that is a system of its own says
system script. Itssystem typelines may appear in its signatures, and its plaintypelines stay its own (Types, A ONE-SCRIPT SYSTEM).
Interfaces anywhere in a system
An interface sits in its own script or beside an item. Like every item's type, it belongs to the whole system, and it compiles to no code. A Boot Script can't hold one.
system script
interface WorldController = {
Enter : () -> ()
Leave : () -> ()
Spawn : () -> ()
ExitStudio : () -> ()
ExitFurniture : () -> ()
}
module WorldControllers = {}
return WorldControllersA standalone types system: one script that says system script, exports its types and returns nothing. Other scripts import them, and a use of it runs nothing and brings them too.
system script
export Disconnectable
interface Disconnectable = {
Disconnect()
}- Any class that implements an interface, or a Roblox class with every member, passes for it: an RBXScriptConnection is a Disconnectable.
useof an interface is an error: there is nothing to require. Import it.- Across systems:
export Payerin the
system script, import Payer from Walletin the other. In a Global it is bare everywhere. Interfaces has the rest.
Many items in one script
A script holds any number of items: classes, modules, interfaces and values. Every one is a full item. Wallet's Purse (THE EXAMPLE) holds three: interface Payer, class Receipt and class Purse.
return Xat the bottom decides what the script hands out, not the item named like the script. It is the script's last statement, and in the
system script it is the system's API. A script with no returnis a blank: it hands out nothing. A forgottenreturnshows up as an error where another script reads the value.- Under
use script.BoardShow, what BoardShow's script hands out is read as BoardShow. If it hands out the class BestBoard,BestBoard.new()gets a row saying BestBoard is the class BoardShow hands out and to read BoardShow, with a fix that writes BoardShow. - The other items are locals of the script: other scripts can't reach their values. Their types belong to the system, so every member of Wallet may write Receipt and Payer, and the
system script may export any of them. - A value is a typed
local, handed out byreturn Xwhen it is what the script hands out. A function needs no type: it takes its type from its typed parameters and return, and every parameter must be typed:
local function NextId(prefix : string) : string- An item takes its file's side.
- A parent class goes above its child in a file.
Boot scripts
A Boot Script is a Script with RunContext Server or Client. It runs on its own when the game starts and returns nothing. It belongs to no system: it declares nothing, can't be required, imports nothing, and reaches systems only through their
system scripts. It takes no system line: one there is an error. Init/Server in THE EXAMPLE is one. Scripts has the rest.
A plugin's Boot Script (a Script with RunContext Plugin) runs in Studio, and a system it uses or starts that nothing but plugin code reaches is plugin code too (Server and client, PLUGIN CODE).
Hidden server code
A server item that clients could reach compiles hidden: a Script (RunContext Server) holding the code, plus a Public ModuleScript stub that stands in for it, and every require goes to the Public. Under ServerStorage or ServerScriptService it stays a plain ModuleScript. ShotScript Editor does it all (Server and client, HIDDEN SERVER CODE).
A plain Luau script requires such an item through its Public and gets the item's own type. Requiring the item itself is a row whose fix adds .Public.
The older forms
An older form is a red row that names the new form, and its fix writes it. Fix all in the place applies those fixes together, only when you press it, and one undo takes it back.
a handed-out server object X local X : T = v and return X, with the script's RunContext Server, in one undoclass X = { and module X = { stay as they are, with no row. The system lines from before (a types line, @types, system module X = { and the rest) are errors in words only, with no fix: each names its new form.
Read next
| Overview | start here |
| Scripts | Boot Scripts in full: Init, their side, the warnings |
| Server and client | sides, side blocks and extensions, a value or a module per side, hidden server code |
| Types | system types, exports and imports |
| Interfaces | interfaces and implements |
| Classes | classes and their members |
| Modules | modules and their members |
| Layouts and sets | layouts and sets |
| Files | paths, use, start and the shape of a script |
| Start order | which Start runs first |
| The shot command | shot wiring and shot refs |
| Rules | the check's rows |
