ServerComm
Types
ServerMiddlewareFn
The middleware function takes the client player and the arguments (as a table array), and should
return true|false
to indicate if the process should continue.
If returning false
, the optional varargs after the false
are used as the new return values
to whatever was calling the middleware.
ServerMiddleware
Array of middleware functions.
Functions
new
Constructs a ServerComm object. The namespace
parameter is used
in cases where more than one ServerComm object may be bound
to the same object. Otherwise, a default namespace is used.
local serverComm = ServerComm.new(game:GetService("ReplicatedStorage"))
-- If many might exist in the given parent, use a unique namespace:
local serverComm = ServerComm.new(game:GetService("ReplicatedStorage"), "MyNamespace")
BindFunction
Creates a RemoteFunction and binds the given function to it. Inbound and outbound middleware can be applied if desired.
local function GetSomething(player: Player)
return "Something"
end
serverComm:BindFunction("GetSomething", GetSomething)
WrapMethod
Binds a function to a table method. The name must match the name of the method in the table. The same name will be used on the client to access the given function.
local MyObject = {
_Data = 10,
}
function MyObject:GetData(player: Player)
return self._Data
end
serverComm:WrapMethod(MyObject, "GetData")
CreateSignal
Creates a signal that can be used to fire data to the clients or receive data from the clients.
local mySignal = serverComm:CreateSignal("MySignal")
-- Examples of firing in different ways (see docs for RemoteSignal for further info):
mySignal:Fire(somePlayer, "Hello world")
mySignal:FireAll("Hi there")
mySignal:FireExcept(somePlayer, "Hello everyone except " .. somePlayer.Name)
mySignal:FireFilter(function(player) return player.Team == someCoolTeam end, "Hello cool team")
-- Example of listening for clients to send data:
mySignal:Connect(function(player, message)
print("Got a message from " .. player.Name .. ":", message)
end)
CreateProperty
ServerComm:
CreateProperty
(
) →
RemoteProperty
Create a property object which will replicate its property value to the clients. Optionally, specific clients can be targeted with different property values.
local comm = Comm.ServerComm.new(game:GetService("ReplicatedStorage"))
local mapInfo = comm:CreateProperty("MapInfo", {
MapName = "TheAwesomeMap",
MapDuration = 60,
})
-- Change the data:
mapInfo:Set({
MapName = "AnotherMap",
MapDuration = 30,
})
-- Change the data for one player:
mapInfo:SetFor(somePlayer, {
MapName = "ASpecialMapForYou",
MapDuration = 90,
})
-- Change data based on a predicate function:
mapInfo:SetFilter(function(player)
return player.Team == game.Teams.SomeSpecialTeam
end, {
MapName = "TeamMap",
MapDuration = 20,
})
Destroy
ServerComm:
Destroy
(
) →
(
)
Destroy the ServerComm object.