ClientRemoteProperty
The clientside counterpart of RemoteProperty. A client remote property in layman's terms is just an object connected to a remote property.
Types
ClientRemoteProperty
Properties
onUpdate
Read onlySignalClientRemoteProperty instanceClientRemoteProperty.onUpdate:
Signal
<
newValue:
any,
oldValue:
any
>
A signal which is fired, whenever the value of the remote property (or the value of the client stored in the remote property) is updated.
Incase the client has a specific value set for them in the remote property, then this signal will only fire if that value has been updated.
Functions
is
ClientRemoteProperty.
is
(
self:
any
) →
boolean
Returns a boolean indicating if self
is a client remote property or not.
get
ClientRemoteProperty instanceClientRemoteProperty:
get
(
) →
T
Returns the value of the client stored in the remote property. If there is no value stored specifically for the client, then the remote property's current value will be returned instead.
observe
ClientRemoteProperty instanceClientRemoteProperty:
observe
(
callback:
(
newValue:
T
,
oldValue:
T?
)
→
(
)
) →
(
)
Observes the value of the client remote property.
clientRemoteProperty:observe(function(newValue, oldValue)
end)
valuePromise
ClientRemoteProperty instanceClientRemoteProperty:
valuePromise
(
valuePredicate:
(
(
newValue:
T
,
oldValue:
T?
)
→
boolean
)
?
) →
(
)
Returns a promise which is resolved with a non-nil value of the client remote property, given
that valuePredicate
is not passed as an argument.
clientRemoteProperty:valuePromise():andThen(function(value)
print(value)
end)
valuePredicate
can ALSO be passed, which allows you to filter out values. If it returns
exactly true
, only then will the promise resolve with the new value.
clientRemoteProperty:valuePromise(function(newValue, oldValue)
print(newValue, oldValue)
return oldValue == 1
end):andThen(function(value)
print(value)
end)
clientRemoteProperty:set(1)
clientRemoteProperty:set(2)
-- Output:
-- 1, nil
-- 2, 1
-- 2
set
ClientRemoteProperty instanceDeprecatedClientRemoteProperty:
set
(
value:
T
) →
(
)
Invokes the remote property, to set the value for the client to value
.
Possible rate limit
It is possible that the client may be rate limited by the server (see RemoteProperty:setRateLimitForClientSettingValue), and thus requests to the server to set the value for the client can possibly be ignored by the server.
-- Server
remoteProperty:setRateLimitForClientSettingValue(client, 30) -- 30 seconds
-- Client
clientRemoteProperty.onUpdate:Connect(function(newValue)
print(newValue)
end)
-- Spam the setting of value for the client, so we ought for the value of the
-- client stored in the remote property (finally) to be `100`, but instead
-- it will be `1`, as subsequent calls after the first one will be ignored
-- due to the rate limit imposed.
for index = 1, 100 do
clientRemoteProperty:set(index)
end
--> 1
Possible Value Set Request Rejection From Server
The server can decline the client's request of setting the value for the client in the remote property. This behavior
will be seen by default, if the remote property has no clientSet
middleware - see DefaultRemotePropertyMiddleware
and RemotePropertyMiddleware for more info.
setPromise
ClientRemoteProperty instanceDeprecatedClientRemoteProperty:
setPromise
(
value:
T
) →
Promise
<
T
>
Works the same as ClientRemoteProperty:set, but returns a promise which is resolved when
the server has set the value for the client to value
, or else rejects with a nil value
. Additionally, the returned promise
resolves with the value that was set. If this method is called againand the returned promise had not yet finished, then the old
promise returned will be cancelled.
Precaution
This method performs a shallow check (self:get() == value
) before informing the server to actually
set the value. This is an attempt to avoid sending unnecessary requests to the server. For e.g:
local thisValue = {1,2,3}
clientRemoteProperty:setPromise(thisValue):expect() -- Assuming this is successful....
warn(clientRemoteProperty:setPromise(thisValue):expect()) -- Does not inform the server, immediately returns a resolved promise!
Possible Promise rejection
This promise can also be rejected with a nil value if the server declines the client's request of setting the value for the client
in the remote property. This behavior will be seen by default, if the remote property has no clientSet
middleware - see DefaultRemotePropertyMiddleware
and RemotePropertyMiddleware for more info.
-- Client
clientRemoteProperty:setPromise(10):andThen(function(newValue)
-- Success!
print(newValue) --> 10
end):catch(function()
-- Server rejected the request
end)
destroy
ClientRemoteProperty instanceClientRemoteProperty:
destroy
(
) →
(
)
Destroys the client remote property and renders it unusable.