ScriptSignal

Overview

Description

The ScriptSignal class is used to manage event-driven programming by emitting and connecting to signals. It allows developers to attach functions (callbacks) to signals, which will be executed when the signal is emitted.

Properties

Constructors

Methods

Connect

Connects a function (callback) to the signal. When the signal is emitted, the connected function will be called.

Parameters

function func

The callback function to connect to the signal. It will be triggered whenever the signal is emitted.

Return

ScriptConnection

Returns a `ScriptConnection` object that can be used to manage the connection to the signal.

Code Samples

local Players = game:GetService("Players")

local function EnterPlayer(player)
    print("EnterPlayer : ", player.Name)
end
Players.PlayerAdded:Connect(EnterPlayer)

Once

Connects a function (callback) to the signal that will only be triggered once. Once the callback function is executed, the connection will automatically disconnect.

Parameters

function func

The callback function to connect to the signal. It will only be triggered the first time the signal is emitted.

Return

ScriptConnection

Returns a `ScriptConnection` object that can be used to manage the connection to the signal.

Code Samples

local Players = game:GetService("Players")

local function EnterPlayer(player)
    print("EnterPlayer : ", player.Name)
end
Players.PlayerAdded:Once(EnterPlayer)

Last updated