🚩 Events
Subscribe for user-defined Events
🎒 Examples
Remote means the other side, e.g.: if I'm the Client, the remote is the Server. If I'm the Server, the remote is the Client.
Basic Usage
-- register for a local Event (local = client only)
Events.Subscribe("MyLocalEvent", function(my_text)
Console.Log("Event received locally! " .. my_text)
-- outputs "Event received locally! hello nanos world!"
end)
-- calls a local Event in all Local Packages
Events.Call("MyLocalEvent", "hello nanos world!")
-- register for a server Event (remote = server)
Events.SubscribeRemote("MyClientEvent", function(my_text)
Console.Log("Event received from server! " .. my_text)
-- outputs "Event received from server! hello nanos world!"
end)
-- calls a remote Event in all Server Packages
Events.CallRemote("MyServerEvent", Reliability.Reliable, "hello nanos world!")
On Server, registering for remote events has an additional first parameter: Player, which is the client who sent the event.
-- register for a local Event (local = server only)
Events.Subscribe("MyLocalEvent", function(my_text)
Console.Log("Event received locally! " .. my_text)
-- outputs "Event received locally! hello nanos world!"
end)
-- calls a local Event in all Local Packages
Events.Call("MyLocalEvent", "hello nanos world!")
-- register for a client Event (remote = client)
Events.SubscribeRemote("MyServerEvent", function(player, my_text)
Console.Log(player:GetName() .. " sent an event from client! " .. my_text)
-- outputs "Syed sent an event from client! hello nanos world!"
-- sends an "answer" to the player which sent this event
Events.CallRemote("MyClientEvent", player, Reliability.Reliable, "hello nanos world! message only for you!")
end)
-- sends a remote Event to all Players in all Client Packages
Events.BroadcastRemote("MyClientEvent", Reliability.Reliable, "hello nanos world!")
Passing entities through Events
-- registers for a local Event
Events.Subscribe("MyEvent", function(my_text, my_vector, my_character, my_number)
Console.Log("Event received! " .. my_text .. " " .. my_vector.X .. " " .. my_character:GetViewMode() .. " " .. my_number)
-- outputs "Event received! hello nanos world! 123 1 456"
end)
-- passing Characters through events
local my_temp_character = Character(Vector(0, 0, 100), Rotator(), "nanos-world::SK_Male")
-- calls a local Event in all Server Packages
Events.Call("MyEvent", "hello nanos world!", Vector(123, 123, 123), my_temp_character, 456)
-- calls a remote Event in all Client Packages of all Players
Events.BroadcastRemote("MyEvent", Reliability.Reliable, "hello nanos world!", Vector(123, 123, 123), my_temp_character, 456)
-- registers for the remote Event, the Character arrives as the same entity on the client
Events.SubscribeRemote("MyEvent", function(my_text, my_vector, my_character, my_number)
Console.Log("Remote event received! %s %s", my_text, tostring(my_character))
end)
Events.Subscribe only receives local events (Events.Call), and Events.SubscribeRemote only receives remote ones. This is the behavior since the version 1.22 (see Compatibility Versions).
You can find more examples and a comprehensive guide at the Events Guide page.
🗿 Static Functions
BroadcastRemote | Broadcasts a remote custom Event from the Server to ALL currently connected Players (Server ➔ Clients) | |
BroadcastRemoteDimension | Broadcasts a remote custom Event from the Server to all Players currently residing in the specified Dimension (Server ➔ Clients) | |
BroadcastRemoteInRadius | Broadcasts a remote custom Event from the Server to all Players within a specific location radius (Server ➔ Clients) | |
BroadcastRemoteInRadiusDimension | Broadcasts a remote custom Event from the Server to all Players within a specific location radius AND residing in a specific Dimension (Server ➔ Clients) | |
Call: boolean | Triggers a local custom Event across all Packages on the same side (Client ➔ Client OR Server ➔ Server) | |
CallRemote | Triggers a remote custom Event from the Client to the Server (Client ➔ Server) | |
CallRemote | Triggers a remote custom Event from the Server to the Client (Server ➔ Client) | |
CallRemotePlayers | Triggers a remote custom Event from the Server to an array of specific Players (Server ➔ Clients) | |
Subscribe: function | Listens for a local custom Event triggered by Events.Call() on the same side | |
SubscribeRemote: function | Listens for a network custom Event | |
Unsubscribe | Removes a local event listener previously registered with Events.Subscribe() | |
UnsubscribeRemote | Removes a network event listener previously registered with Events.SubscribeRemote() |

BroadcastRemoteModerate
Broadcasts a remote custom Event from the Server to ALL currently connected Players (Server ➔ Clients)
Must be caught using Events.SubscribeRemote() on the Clients
Events.BroadcastRemote(event_name, reliability?, args...?)
Parameters
| Name | Type | Descrição |
|---|---|---|
event_name | string | The Event Name to trigger the event |
reliability? | Reliability | The network reliability rule Default Reliability.Reliable |
args...? | any | Arguments to pass to the event Default nil |
See also SubscribeRemote.

BroadcastRemoteDimensionModerate
Broadcasts a remote custom Event from the Server to all Players currently residing in the specified Dimension (Server ➔ Clients)
Must be caught using Events.SubscribeRemote() on the Clients
Events.BroadcastRemoteDimension(event_name, dimension, reliability?, args...?)
Parameters
| Name | Type | Descrição |
|---|---|---|
event_name | string | The Event Name to trigger the event |
dimension | integer | The Dimension to send this event |
reliability? | Reliability | The network reliability rule Default Reliability.Reliable |
args...? | any | Arguments to pass to the event Default nil |
See also SubscribeRemote.

BroadcastRemoteInRadiusModerate
Broadcasts a remote custom Event from the Server to all Players within a specific location radius (Server ➔ Clients)
Must be caught using Events.SubscribeRemote() on the Clients
Events.BroadcastRemoteInRadius(event_name, location, radius, reliability?, args...?)
Parameters
| Name | Type | Descrição |
|---|---|---|
event_name | string | The Event Name to trigger the event |
location | Vector | The location used to calculate the event radius |
radius | number | The radius to send this event |
reliability? | Reliability | The network reliability rule Default Reliability.Reliable |
args...? | any | Arguments to pass to the event Default nil |
See also SubscribeRemote.

BroadcastRemoteInRadiusDimensionModerate
Broadcasts a remote custom Event from the Server to all Players within a specific location radius AND residing in a specific Dimension (Server ➔ Clients)
Must be caught using Events.SubscribeRemote() on the Clients
Events.BroadcastRemoteInRadiusDimension(event_name, location, radius, dimension, reliability?, args...?)
Parameters
| Name | Type | Descrição |
|---|---|---|
event_name | string | The Event Name to trigger the event |
location | Vector | The location used to calculate the event radius |
radius | number | The radius to send this event |
dimension | integer | The Dimension to send this event |
reliability? | Reliability | The network reliability rule Default Reliability.Reliable |
args...? | any | Arguments to pass to the event Default nil |
See also SubscribeRemote.

CallModerate
Triggers a local custom Event across all Packages on the same side (Client ➔ Client OR Server ➔ Server)
Must be caught using Events.Subscribe()
local ret = Events.Call(event_name, args...?)
Parameters
| Name | Type | Descrição |
|---|---|---|
event_name | string | The Event Name to trigger the event |
args...? | any | Arguments to pass to the event Default nil |
Returns
| Type | Descrição |
|---|---|
| boolean | Returns false if any of the event listeners returned false, otherwise returns true |
See also Subscribe.

CallRemoteModerate
Triggers a remote custom Event from the Client to the Server (Client ➔ Server)
The receiving Server will implicitly receive the sender 'Player' as the very first argument before your custom args
Must be caught using Events.SubscribeRemote()
Events.CallRemote(event_name, reliability?, args...?)
Parameters
| Name | Type | Descrição |
|---|---|---|
event_name | string | The Event Name to trigger the event |
reliability? | Reliability | The network reliability rule Default Reliability.Reliable |
args...? | any | Arguments to pass to the event Default nil |
See also SubscribeRemote.

CallRemoteModerate
Triggers a remote custom Event from the Server to the Client (Server ➔ Client)
Must be caught using Events.SubscribeRemote()
Events.CallRemote(event_name, player, reliability?, args...?)
Parameters
| Name | Type | Descrição |
|---|---|---|
event_name | string | The Event Name to trigger the event |
player | Player | The remote player to send this event |
reliability? | Reliability | The network reliability rule Default Reliability.Reliable |
args...? | any | Arguments to pass to the event Default nil |
See also SubscribeRemote.

CallRemotePlayersModerate
Triggers a remote custom Event from the Server to an array of specific Players (Server ➔ Clients)
More network-efficient than looping CallRemote
Must be caught using Events.SubscribeRemote() on the Clients
Events.CallRemotePlayers(event_name, players, reliability?, args...?)
Parameters
| Name | Type | Descrição |
|---|---|---|
event_name | string | The Event Name to trigger the event |
players | table of Player | The remote players to send this event |
reliability? | Reliability | The network reliability rule Default Reliability.Reliable |
args...? | any | Arguments to pass to the event Default nil |
See also SubscribeRemote.

SubscribeOptimal
Listens for a local custom Event triggered by Events.Call() on the same side
local ret = Events.Subscribe(event_name, callback)
Parameters
| Name | Type | Descrição |
|---|---|---|
event_name | string | The Event Name to subscribe |
callback | function | The callback function to execute |
Returns
| Type | Descrição |
|---|---|
| function | the subscribed callback itself |

SubscribeRemoteOptimal
Listens for a network custom Event
If on the Server, it catches Events.CallRemote() from Clients (receiving the sender 'Player' as the first argument)
If on the Client, it catches Server broadcasts and remote calls
local ret = Events.SubscribeRemote(event_name, callback)
Parameters
| Name | Type | Descrição |
|---|---|---|
event_name | string | The Event Name to subscribe |
callback | function | The callback function to execute |
Returns
| Type | Descrição |
|---|---|
| function | the subscribed callback itself |

UnsubscribeOptimal
Removes a local event listener previously registered with Events.Subscribe()
If no specific callback function is passed, it removes ALL local listeners for that event name in the current Package
Events.Unsubscribe(event_name, callback?)

UnsubscribeRemoteOptimal
Removes a network event listener previously registered with Events.SubscribeRemote()
If no specific callback function is passed, it removes ALL remote listeners for that event name in the current Package
Events.UnsubscribeRemote(event_name, callback?)

