Script
Code that runs on the game server. Players never receive it.
- Inherits: Instance
- Subclasses: LocalScript
- Creatable: No. Scripts are added in Rally Studio; game code can’t create code while the game runs.
- Replication: Server only: it, and everything inside it, is never sent to clients.
A Script holds TypeScript you write in Rally Studio. It runs on the game server if it’s inside
the Workspace or ServerScriptService and enabled: when the game starts, or, for a script that
gets there later (a clone, say), when it’s added. Scripts anywhere else don’t run.
A script runs once, top to bottom. Its top-level code should set things up and return quickly:
work that goes on (loops, timers, waiting) belongs in event handlers and
task. Errors in a script, its handlers and its tasks are written to the
game’s output and never stop the game or other scripts. Inside a script, the
script export is the Script itself, so a script inside a part
can reach it with script.parent.
LocalScript is a subclass of Script, so instanceof Script is also
true for LocalScripts.
Properties
Section titled “Properties”source
Section titled “source”Type: string · Default: '' · Access: read-only · Replicates: no
The script’s code. Game code can’t change it; while the game runs it holds the compiled JavaScript.
enabled
Section titled “enabled”Type: boolean · Default: true · Access: read/write · Replicates: no
When false, the script doesn’t run. A script starts when the game starts, or when it’s added (or
moved) somewhere scripts run, if enabled is true at that moment. Changing enabled afterwards
doesn’t stop a script that’s running.
Inherited from Instance: name, archivable, id, className, parent, destroyed
Methods
Section titled “Methods”Inherited from Instance: getPropertyChangedSignal, setAttribute, getAttribute, getAttributes, getAttributeChangedSignal, getChildren, getDescendants, findFirstChild, findFirstChildOfClass, findFirstChildWhichIsA, findFirstAncestor, findFirstAncestorWhichIsA, waitForChild, isA, isDescendantOf, isAncestorOf, getFullName, clearAllChildren, destroy, clone, toString
Events
Section titled “Events”Inherited from Instance: changed, childAdded, childRemoved, descendantAdded, descendantRemoving, ancestryChanged, destroying, attributeChanged
Examples
Section titled “Examples”A script inside a part
Section titled “A script inside a part”import { BasePart, Character, script } from '@rally/sdk';
// This Script sits inside a part in the Workspace: touching the part heals.const pad = script.parent;if (pad instanceof BasePart) { pad.touched.connect((other) => { if (other instanceof Character) other.health = other.maxHealth; });}