NativeSignal:Once Synchronous

Listen for the next firing of a runtime-backed event, then disconnect the listener. Use it for one event, such as the first response on a connection. The handler is removed after that event, so later messages need another subscription.

Syntax
Luau
NativeSignal:Once(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
callbackFunctionOne-shot handler. The owning event determines its arguments.

Returns

RBXScriptConnection

An RBXScriptConnection.

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:Once(function(message)
    print("Received:", message)
end)
socket:Send("example message")
task.wait(2)
listener:Disconnect()
socket:Close()
Kawaii documentation