NativeSignal:Connect Synchronous

Listen to a runtime-backed event, such as a WebSocket message or close event. Use it to process repeated events for as long as the owning resource is active. Keep the returned connection and disconnect it during cleanup.

Syntax
Luau
NativeSignal:Connect(callback: Function) -> RBXScriptConnection

Parameters

Call this method with a NativeSignal receiver. The colon supplies self implicitly; a dot call must pass the receiver explicitly.

Function parameters
ParameterTypeDescription
callbackFunctionEvent handler. The owning event determines its arguments.

Returns

RBXScriptConnection

An RBXScriptConnection that can be disconnected when no longer needed.

Usage notes

This is an event wrapper supplied by another API, not a separately constructed Signal.new object.

Example

Example
Luau
-- Requires an echo server you control at this address.
local socket = WebSocket.connect("ws://127.0.0.1:8765")
local listener = socket.OnMessage:Connect(function(message)
    print("Received:", message)
end)
socket:Send("example message")
task.wait(2)
listener:Disconnect()
socket:Close()
Kawaii documentation