RemoteProperty
Created via ServerComm:CreateProperty()
.
Values set can be anything that can pass through a RemoteEvent.
Here is a cheat-sheet for the below methods:
- Setting data
Set
: Set "top" value for all current and future players. Overrides any custom-set data per player.SetTop
: Set the "top" value for all players, but does not override any custom-set data per player.SetFor
: Set custom data for the given player. Overrides the "top" value. (Can be nil)SetForList
: Same asSetFor
, but accepts a list of players.SetFilter
: Accepts a predicate function which checks for which players to set.
- Clearing data
ClearFor
: Clears the custom data set for a given player. Player will start using the "top" level value instead.ClearForList
: Same asClearFor
, but accepts a list of players.ClearFilter
: Accepts a predicate function which checks for which players to clear.
- Getting data
Get
: Retrieves the "top" valueGetFor
: Gets the current value for the given player. If cleared, returns the top value.
Network
Calling any of the data setter methods (e.g. Set()
) will
fire the underlying RemoteEvent to replicate data to the
clients. Therefore, setting data should only occur when it
is necessary to change the data that the clients receive.
Tables
Tables can be used with RemoteProperties. However, the RemoteProperty object will not watch for changes within the table. Therefore, anytime changes are made to the table, the data must be set again using one of the setter methods.
Functions
Set
RemoteProperty:
Set
(
value:
any
) →
(
)
Sets the top-level value of all clients to the same value.
Override Per-Player Data
This will override any per-player data that was set using
SetFor
or SetFilter
. To avoid overriding this data,
SetTop
can be used instead.
-- Examples
remoteProperty:Set(10)
remoteProperty:Set({SomeData = 32})
remoteProperty:Set("HelloWorld")
SetTop
RemoteProperty:
SetTop
(
value:
any
) →
(
)
Set the top-level value of the property, but does not override
any per-player data (e.g. set with SetFor
or SetFilter
).
Any player without custom-set data will receive this new data.
This is useful if certain players have specific values that should not be changed, but all other players should receive the same new value.
-- Using just 'Set' overrides per-player data:
remoteProperty:SetFor(somePlayer, "CustomData")
remoteProperty:Set("Data")
print(remoteProperty:GetFor(somePlayer)) --> "Data"
-- Using 'SetTop' does not override:
remoteProperty:SetFor(somePlayer, "CustomData")
remoteProperty:SetTop("Data")
print(remoteProperty:GetFor(somePlayer)) --> "CustomData"
SetFilter
RemoteProperty:
SetFilter
(
value:
any
--
Value to set for the clients (and to the predicate)
) →
(
)
Sets the value for specific clients that pass the predicate
function test. This can be used to finely set the values
based on more control logic (e.g. setting certain values
per team).
-- Set the value of "NewValue" to players with a name longer than 10 characters:
remoteProperty:SetFilter(function(player)
return #player.Name > 10
end, "NewValue")
SetFor
Set the value of the property for a specific player. This
will override the value used by Set
(and the initial value
set for the property when created).
This value can be nil
. In order to reset the value for a
given player and let the player use the top-level value held
by this property, either use Set
to set all players' data,
or use ClearFor
.
remoteProperty:SetFor(somePlayer, "CustomData")
SetForList
Set the value of the property for specific players. This just
loops through the players given and calls SetFor
.
local players = {player1, player2, player3}
remoteProperty:SetForList(players, "CustomData")
ClearFor
Clears the custom property value for the given player. When
this occurs, the player will reset to use the top-level
value held by this property (either the value set when the
property was created, or the last value set by Set
).
remoteProperty:Set("DATA")
remoteProperty:SetFor(somePlayer, "CUSTOM_DATA")
print(remoteProperty:GetFor(somePlayer)) --> "CUSTOM_DATA"
-- DOES NOT CLEAR, JUST SETS CUSTOM DATA TO NIL:
remoteProperty:SetFor(somePlayer, nil)
print(remoteProperty:GetFor(somePlayer)) --> nil
-- CLEAR:
remoteProperty:ClearFor(somePlayer)
print(remoteProperty:GetFor(somePlayer)) --> "DATA"
ClearForList
Clears the custom value for the given players. This
just loops through the list of players and calls
the ClearFor
method for each player.
ClearFilter
The same as SetFiler
, except clears the custom value
for any player that passes the predicate.
Get
RemoteProperty:
Get
(
) →
any
Returns the top-level value held by the property. This will
either be the initial value set, or the last value set
with Set()
.
remoteProperty:Set("Data")
print(remoteProperty:Get()) --> "Data"
GetFor
Returns the current value for the given player. This value
will depend on if SetFor
or SetFilter
has affected the
custom value for the player. If so, that custom value will
be returned. Otherwise, the top-level value will be used
(e.g. value from Set
).
-- Set top level data:
remoteProperty:Set("Data")
print(remoteProperty:GetFor(somePlayer)) --> "Data"
-- Set custom data:
remoteProperty:SetFor(somePlayer, "CustomData")
print(remoteProperty:GetFor(somePlayer)) --> "CustomData"
-- Set top level again, overriding custom data:
remoteProperty:Set("NewData")
print(remoteProperty:GetFor(somePlayer)) --> "NewData"
-- Set custom data again, and set top level without overriding:
remoteProperty:SetFor(somePlayer, "CustomData")
remoteProperty:SetTop("Data")
print(remoteProperty:GetFor(somePlayer)) --> "CustomData"
-- Clear custom data to use top level data:
remoteProperty:ClearFor(somePlayer)
print(remoteProperty:GetFor(somePlayer)) --> "Data"
Destroy
RemoteProperty:
Destroy
(
) →
(
)
Destroys the RemoteProperty object.