SendToClient||doc136357

September 20, 2022

Format

PackageHandlers:SendToClient(player, packetName, packet)

Describe

The server sends the protocol to a single client.

parameter

Variable name Type Describe
player Entity Player entity
packetName string Protocol name, corresponding to the receiving function
packet table<variant> The parameter carried by the protocol is an empty table by default

The passed in player entity must be a player entity

Parameter type in packet can only beBasic type

Code example

The server sends the "testpackage" protocol with two parameters

-- player is the player entity, the acquisition process is omitted here

-- carry parameters
local packet = {
     a = 1,
     b = 2
}

-- send protocol
PackageHandlers:SendToClient(player, "TestPackage", packet)

Client receives "testpackage" protocol

-- receive protocol
-- player : client player entity
-- packet : The parameters that the server carries when sending the protocol
PackageHandlers:Receive("TestPackage", function(player, packet)
     print("client receive package", player)
     print(packet.a, packet.b)
end)