Skip to content

ComponentSignal

Type

ComponentSignal is a world-wide signal on a component handle, such as Component.User.Added, Component.User.Removed, or Component.Button.Clicked. Handlers receive the entity first followed by any signal payload arguments. To listen on one entity, pass the same handle to entity:On(signal, fn).

Connect

Field
Connect: ComponentSignalConnectFn

Connect runs fn every time the signal fires on any entity, passing the entity followed by the payload values, and returns a Connection.

Example

-- Server script.
local conn = Component.User.Added:Connect(function(player: Entity)
    print(player.Name)
end)
conn:Disconnect()

Once

Field
Once: ComponentSignalConnectFn

Once runs fn the next time the signal fires on any entity, then disconnects it, and returns a Connection.

Example

-- Server script.
Component.User.Added:Once(function(player: Entity)
    print("first joiner:", player.Name)
end)

Wait

Field
Wait: ComponentSignalWaitFn

Wait yields until the signal next fires on any entity or seconds pass, returning true, the entity, and the payload values on fire, or false on timeout.

Example

-- Server script.
task.spawn(function()
    local ok, player = Component.User.Added:Wait(30)
    if ok and player then
        print(player.Name)
    end
end)