Skip to content

Signal

Type

Signal runs functions when a service or object event fires, such as Chat.MessageSent, Input.Pressed, or tween.Finished. For entity and component lifecycle signals, use entity:On(Component.<Name>.<Signal>, fn) or Component.<Name>.Added:Connect(fn).

Connect

Method
Connect(fn: (T...) -> ()) -> Connection

Connect runs a function every time the signal emits, until it is disconnected or its owner ends, and returns a Connection with Connected and Disconnect. Each call runs on its own thread, so it may call task.wait, and an error in one function does not stop the others.

Example

-- Server script.
local conn = Chat.MessageSent:Connect(function(player: Entity, text: string)
    print(player.Name .. ": " .. text)
end)
conn:Disconnect()

Once

Method
Once(fn: (T...) -> ()) -> Connection

Once runs a function the next time the signal emits, then disconnects it, and returns a Connection.

Example

-- Server script.
Chat.MessageSent:Once(function(player: Entity, text: string)
    print("first message:", player.Name, text)
end)

Wait

Method
Wait(seconds: number?) -> (boolean, T...)

Wait pauses the script until the signal next emits, then returns true followed by the emitted values. Pass seconds to stop waiting after that many seconds. Wait returns false when the time runs out or the signal's owner ends, and Wait(0) returns false at once. It cannot pause Update or another callback that must return at once; call it from the top of the script or from task.spawn.

Example

-- Server script.
task.spawn(function()
    local ok, player, text = Chat.MessageSent:Wait(30)
    if ok then
        print(player, text)
    end
end)