Signal
An event: connect a function to it, and the function runs every time the event fires.
- Get it: every event (
part.touched,Players.playerAdded, …) is one
Every event in the API is a Signal: part.touched, Players.playerAdded,
RunService.heartbeat and the rest. Each event’s page lists the arguments its handlers receive.
A handler that throws, or an async handler that rejects, is reported in the game’s output and
never stops the other handlers. Handlers connected while the signal is firing first run on its
next fire. Destroying an instance disconnects every handler of its events.
Methods
Section titled “Methods”connect
Section titled “connect”connect(fn: (...args: Args) => unknown): ConnectionCalls fn every time the signal fires until the returned connection is disconnected.
once(fn: (...args: Args) => unknown): ConnectionCalls fn the next time the signal fires, then disconnects.
wait(): Promise<Args>Resolves with the arguments of the next fire.
Examples
Section titled “Examples”Connect, once, wait and disconnect
Section titled “Connect, once, wait and disconnect”import { Part, Players, getChild, print, task, workspace } from '@rally/sdk';
const pad = getChild(workspace, 'Pad', Part);const connection = pad.touched.connect((other) => print('touched by', other));
Players.playerAdded.once((player) => print('first player:', player.displayName));
task.spawn(async () => { const [player] = await Players.playerAdded.wait(); print('next player:', player.displayName); connection.disconnect(); // stop listening to the pad});