raknet.OnPacketReceive:Once Synchronous

  • RakNet.OnPacketReceive:Once

Observe just the next incoming packet. The one-shot connection unregisters before the callback, so the callback cannot accidentally receive a second packet.

Syntax
Luau
raknet.OnPacketReceive:Once(callback: (RakNetPacket) -> ()) -> RakNetConnection

Parameters

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

Function parameters
ParameterTypeDescription
callback(RakNetPacket) -> ()Function called once with a temporary RakNetPacket.

Argument fields

RakNetPacket fields
Luau
RakNetPacket = {
  Data: buffer, AsArray: {number}, AsBuffer: buffer, AsString: string,
  Size: number, PacketId: number, ID: number, Id: number, PacketID: number, Priority: number,
  Reliability: number, OrderingChannel: number,
  SystemIdentifier: string, Broadcast: boolean, ForceReceiptNumber: number
}

Returns

RakNetConnection

A RakNetConnection that can also be disconnected before it fires.

RakNetConnection fields
Luau
RakNetConnection = {Connected: boolean, Disconnect: Function, disconnect: Function}

Usage notes

The RakNet library must be enabled in Environment settings and connected to an active game generation.

Callbacks must not yield. If a callback raises, Kawaii reports a warning and continues dispatching.

The RakNetPacket view is valid only during its callback. Save fields or copy Data inside the callback if you need them later.

Availability

RakNet is disabled by default. RakNet and raknet are removed when the setting is off; retained references can still call is_enabled().

Example

Example
Luau
if raknet.is_enabled() then
    local connection = raknet.OnPacketReceive:Once(function(packet)
        print("Next incoming ID:", packet.ID)
    end)
    task.delay(10, function() connection:Disconnect() end)
end
Kawaii documentation