ClientPlayerDataManager
This class is used to provide a simple unified interface for accessing PlayerData. It requires registering what data it should expect and then you can access the data's managers once they have replicated.
-- this should usually be gotten from a shared module between the server and client
local ProfileTemplate = {
Currency = {
Money = 0,
Gems = 100,
}
}
local cpdm = ClientPlayerDataManager.new({
ProfileSchema = ProfileTemplate
})
cpdm:RegisterManager("Currency")
cpdm:PromiseManager("Currency"):andThen(function(tm: TableManager)
tm:Observe("Money", function(money)
print("My money is:", money)
end)
end)
Properties
DEFAULT_MANAGER_NAME
ClientPlayerDataManager.DEFAULT_MANAGER_NAME:
string
The default internal manager name.
PlayerDataReady
A signal that fires when a Player's data is ready to be used.
Functions
new
ConstructorStaticGetImmediate
Gets the TableReplicatorSingleton for this manager so you can get immediate info from it if needed.
GetManager
Gets the TableManager associated with the given name. This method may return nil
if the
data has not replicated yet.
PromiseManager
ClientPlayerDataManager:
PromiseManager
(
managerName:
string?
) →
Promise
Promises the TableManager associated with the given name. If it doesnt exist when called then it will wait for it to be replicated and then will resolve.
RegisterManager
ClientPlayerDataManager:
RegisterManager
(
config:
string
|
{
Name:
string;
DefaultDataSchema:
table;
ConditionFn:
(
(
replicator:
TableReplicator
)
→
boolean
)
?
}
) →
TableReplicatorSingleton
Registers a tableManager/TableReplicatorSingleton to be watched for on the client.
Informal registration. Assumes data key in the profile template is the same as the given name.
ClientPlayerDataManager:RegisterManager("Currency")
Formal registration. Used for more complex/custom registering of managers. Equivalent to the above
ClientPlayerDataManager:RegisterManager({
Name = "Currency",
DefaultDataSchema = profileTemplate["Currency"],
ConditionFn = function(replicator)
return replicator:GetTag("UserId") == LocalPlayer.UserId
end,
})
Start
ClientPlayerDataManager:
Start
(
) →
(
)
Marks the CPDM as started. This is not currently neccessary