Server Server Only Since 1.0.0
The server namespace object. This object is returned by Red.Server
and is used for networking on the server.
Methods
Fire Server Only Since 1.0.0
Fires an event to a single client.
(
Player: Player, -- The player to fire the event to.
Event: string, -- The name of the event to fire.
...: any -- The arguments to pass to the event.
)
WARNING
This method has the same data limits as RemoteEvent
. Any data that cannot be serialized will arrive malformed on the client.
local Net = Red.Server("NamespaceName", { "EventName" })
Net:Fire(Player, "EventName", "Hello, world!")
FireAll Server Only Since 1.0.0
Fires an event to all clients.
(
Event: string, -- The name of the event to fire.
...: any -- The arguments to pass to the event.
)
WARNING
This method has the same data limits as RemoteEvent
. Any data that cannot be serialized will arrive malformed on the client.
local Net = Red.Server("NamespaceName", { "EventName" })
Net:FireAll("EventName", "Hello, world!")
FireAllExcept Server Only Since 1.0.0
Fires an event to all clients except one.
(
Player: Player, -- The player to not fire the event to.
Event: string, -- The name of the event to fire.
...: any -- The arguments to pass to the event.
)
WARNING
This method has the same data limits as RemoteEvent
. Any data that cannot be serialized will arrive malformed on the client.
local Net = Red.Server("NamespaceName", { "EventName" })
Net:FireAllExcept(Player, "EventName", "Hello, world!")
FireList Server Only Since 1.0.0
Fires an event to a list of clients.
(
Players: { Player }, -- The players to fire the event to.
Event: string, -- The name of the event to fire.
...: any -- The arguments to pass to the event.
)
WARNING
This method has the same data limits as RemoteEvent
. Any data that cannot be serialized will arrive malformed on the client.
local Net = Red.Server("NamespaceName", { "EventName" })
Net:FireList({ Player1, Player2 }, "EventName", "Hello, world!")
FireWithFilter Server Only Since 1.0.0
Fires an event to a list of clients, with a filter.
(
Filter: (Player) -> boolean, -- The filter to use to determine which players to fire the event to.
Event: string, -- The name of the event to fire.
...: any -- The arguments to pass to the event.
)
WARNING
This method has the same data limits as RemoteEvent
. Any data that cannot be serialized will arrive malformed on the client.
local Net = Red.Server("NamespaceName", { "EventName" })
Net:FireWithFilter(function(Player)
return Player.Name == "Player1"
end, "EventName", "Hello, world!")
On Server Only Since 1.0.0
Registers a callback for an event.
(
Event: string, -- The name of the event to register a callback for.
Callback: ((Player, ...: any) -> (...any))? -- The callback to register.
)
Each event can only have one callback. An attempt to register a second callback will overwrite the first. To remove a callback, pass nil
as the callback. You do not need to register the event names in the constructor.
The passed function will also be used for calls. If the client requests a call, any returned values from the callback will be sent back to the client.
local Net = Red.Server("NamespaceName")
Net:On("EventName", function(Player, Message)
print(Player.Name .. " said: " .. Message)
end)
Folder Server Only Since 1.0.0
Retrieves a shared namespace folder.
(
Player: Player? -- The (optional) player to get the folder for.
)
This method returns a Folder
that is shared between the server and the client. This folder can be used to store data that is shared between the server and the client.
If you specify the optional Player
argument, the folder will only be shared with that player. Otherwise, the folder will be shared with all players.
How is this possible?
Folders that replicate to single players are done by using their PlayerGui. Anything there is replicated to that player only. Red cleans up the folder so you will find no trace of it in the PlayerGui.
local Net = Red.Server("NamespaceName")
local Folder = Net:Folder()
-- Attributes are suggested in place of remote
-- values as they are more efficient.
Folder:SetAttribute("Attribute", 10)