raknet.OnPacketReceive:Wait Asynchronous

  • RakNet.OnPacketReceive:Wait

Yield until the next incoming packet and receive a copied snapshot. This is useful when a coroutine needs one packet’s data after its event callback has finished.

Syntax
Luau
raknet.OnPacketReceive:Wait() -> PacketSnapshot

Parameters

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

This function takes no arguments.

Returns

PacketSnapshot

An owned PacketSnapshot table with a buffer in Data and packet metadata.

PacketSnapshot fields
Luau
PacketSnapshot = {
  Data: buffer, Priority: number, Reliability: number, OrderingChannel: number,
  SystemIdentifier: string, Broadcast: boolean, ForceReceiptNumber: number
}

Usage notes

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

The wait can remain suspended until matching traffic arrives.

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
    task.spawn(function()
        local packet = raknet.OnPacketReceive:Wait()
        print("Next incoming payload bytes:", buffer.len(packet.Data))
    end)
end
Kawaii documentation