SendToAllClients||doc136358

September 20, 2022

Format

PackageHandlers:SendToAllClients(packetName, packet)

Describe

The server sends protocols to all clients.

parameter

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

Parameter type in packet can only beBasic type

Code example

The server sends the "testpackage" protocol with two parameters

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

-- send protocol
PackageHandlers:SendToAllClients("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)