network.create

Creates a packet from its schema.

Syntax

Signature
network.create(Type: number | string, Fields: table?) -> Packet

Aliases

  • raknet.create
  • packets.create
  • RakNet.create

Parameters

ParameterTypeDescription
Typenumber | stringPacket ID from 0 through 63, or exact type name from network.gettypes().
Fieldstable?Decoded fields to merge into the codec defaults.

Returns

TypeDescription
PacketNew packet object.

Notes

Fields optionally overrides those defaults using a JSON merge patch. Returns a mutable packet object. Unknown IDs, unsupported schemas, and invalid fields raise errors.

Example

Luau
local Packet = network.create("Chat", {
    sender_id = "0",
    username = "Example",
    text = "Hello",
})

print(Packet.type, Packet.PacketId, Packet.Size)
print(Packet.decoded.text)
-- Creating a packet does not send it.