Skip to content

NetworkEvent

NetworkEvents are events that can be called to communicate between server and client. NetMessages are the class used for sharing data between server and client when sending NetworkEvents.

Inherits Instance

Events

InvokedClient

Parameters

sender [ nil ]

netmsg [ NetMessage ]

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

Parameters

sender [ Player ]

netmsg [ NetMessage ]

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

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)

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.

InvokeClient → void

Parameters

message [ NetMessage ]

player [ Player ]

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.