Skip to content

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.

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

Inherited from Instance: getPropertyChangedSignal, setAttribute, getAttribute, getAttributes, getAttributeChangedSignal, getChildren, getDescendants, findFirstChild, findFirstChildOfClass, findFirstChildWhichIsA, findFirstAncestor, findFirstAncestorWhichIsA, waitForChild, isA, isDescendantOf, isAncestorOf, getFullName, clearAllChildren, destroy, clone, toString

Inherited from Instance: changed, childAdded, childRemoved, descendantAdded, descendantRemoving, ancestryChanged, destroying, attributeChanged

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';
}
});