LocalScript
Code that runs on each player’s device.
- Inherits: Script → Instance
- Creatable: No. Scripts are added in Rally Studio; game code can’t create code while the game runs.
- Replication: Replicated, with its code: players’ devices need it to run it.
A LocalScript runs on a player’s device if it’s inside StarterPlayerScripts, or inside that player: in practice their PlayerGui, where LocalScripts in a ScreenGui in StarterGui are copied when the player joins. Anywhere else, including the Workspace, it doesn’t run.
Use LocalScripts for input, the camera, UI and effects. Changes a LocalScript makes to the world stay on that device: to change the shared game, ask the server with a RemoteEvent. A LocalScript’s code, and the code of every ModuleScript it imports, is sent to players, so never put secrets in it.
Properties
Section titled “Properties”source
Section titled “source”Type: string · Default: '' · Access: read-only · Replicates: yes
The script’s code, sent to every player’s device. Game code can’t change it.
Inherited from Script: enabled
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”Switch to a view from above
Section titled “Switch to a view from above”import { Players, UserInputService, Vector3, workspace } from '@rally/sdk';
// Press V to switch between the normal camera and a view from above. Only this player sees it.UserInputService.inputBegan.connect((input, gameProcessed) => { if (gameProcessed || input.key !== 'KeyV') return; const camera = workspace.currentCamera; const character = Players.localPlayer?.character; if (!camera || !character) return; if (camera.cameraType === 'follow') { camera.cameraType = 'scriptable'; camera.position = character.position.add(new Vector3(0, 60, 1)); camera.lookAt = character.position; } else { camera.cameraType = 'follow'; }});