NetworkEvent¶
NetworkEvents are events that can be called to communicate between server and client. NetMessage are the class used for sharing data between server and client when sending NetworkEvents.
Inherits Instance
Events¶
InvokedClient¶
Fires when the client receives a message from the server.
Example
netEvent.InvokedClient:Connect(function (sender, message)
local value = message:GetString("key")
end)
This is only available to the client. It can only be accessed within local scripts.
InvokedServer¶
Fires when the server receives a message from the client.
Example
netEvent.InvokedServer:Connect(function (sender, message)
local value = message:GetString("key")
end)
This is only available to the server. It can only be accessed within server scripts.
Methods¶
InvokeClient → void
¶
Sends a network event to a specific player from the server.
Example
local message = NetMessage.New()
message.AddString("key", "value")
netEvent.InvokeClient(message, game["Players"]["willemsteller"])
This is only available to the server. It can only be accessed within server scripts.
InvokeClients → void
¶
Parameters: message [ NetMessage ]
Sends a network event to all players from the server.
Example
local message = NetMessage.New()
message.AddString("key", "value")
netEvent.InvokeClients(message)
This is only available to the server. It can only be accessed within server scripts.
InvokeServer → void
¶
Parameters: message [ NetMessage ]
Sends a network event to the server from the client.
Example
-- netEvent defined somewhere else in the code
local message = NetMessage.New()
message.AddString("key", "value")
netEvent.InvokeServer(message)