Listening to Packet Events
Listening to a Packet Event allows you to run code whenever a packet is received.
Packet Events use :Connect() to create listeners.
Connecting to Events
Section titled “Connecting to Events”Use :Connect() to listen for incoming events.
Example:
Network.Server.OpenRewardMenu:Connect(function(data) print(data.rewardId)end)Whenever the event is fired, the callback will run with the received data.
Server Event Listeners
Section titled “Server Event Listeners”Server-owned events are received by the client.
Example schema:
Server = { OpenRewardMenu = Packeteer.event<<{ rewardId: number }>>(),}Client:
Network.Server.OpenRewardMenu:Connect(function(data) print("Opening reward menu:", data.rewardId)end)The callback receives the exact data defined in the schema.
Client Event Listeners
Section titled “Client Event Listeners”Client-owned events are received by the server.
Example Schema:
Client = { EquipItem = Packeteer.event<<{ itemId: string }>>(),}Server:
Network.Client.EquipItem:Connect(function(player, data) print(player.Name, "equipped", data.itemId)end)When the server receives a client-owned event, Packeteer automatically provides the sending Player as the first callback argument.
Disconnecting Listeners
Section titled “Disconnecting Listeners”:Connect() returns a RBXScriptConnection.
You can disconnect a listener when it is no longer needed.
local connection = Network.Server.OpenRewardMenu:Connect(function(data) print(data.rewardId)end)
connection:Disconnect()Disconnecting a connection prevents the callback from running in the future.
