PlayerDataStoreManager
This item only works when running on the server. Server
DataStore manager for player that automatically saves on player leave and game close.
tip
Consider using PlayerDataStoreService instead, which wraps one PlayerDataStoreManager.
This will ensure that the datastores are reused between different services and other things integrating with Nevermore.
local serviceBag = ServiceBag.new()
local playerDataStoreService = serviceBag:GetService(require("PlayerDataStoreService"))
serviceBag:Init()
serviceBag:Start()
local topMaid = Maid.new()
local function handlePlayer(player)
local maid = Maid.new()
local playerMoneyValue = Instance.new("IntValue")
playerMoneyValue.Name = "Money"
playerMoneyValue.Value = 0
playerMoneyValue.Parent = player
maid:GivePromise(playerDataStoreService:PromiseDataStore(Players)):Then(function(dataStore)
maid:GivePromise(dataStore:Load("money", 0))
:Then(function(money)
playerMoneyValue.Value = money
maid:GiveTask(dataStore:StoreOnValueChange("money", playerMoneyValue))
end)
end)
topMaid[player] = maid
end
Players.PlayerAdded:Connect(handlePlayer)
Players.PlayerRemoving:Connect(function(player)
topMaid[player] = nil
end)
for _, player in pairs(Players:GetPlayers()) do
task.spawn(handlePlayer, player)
end
Functions
new
PlayerDataStoreManager.
new
(
keyGenerator:
(
player
)
→
string
,
--
Function that takes in a player, and outputs a key
skipBindingToClose:
boolean?
) →
PlayerDataStoreManager
Constructs a new PlayerDataStoreManager.
DisableSaveOnCloseStudio
PlayerDataStoreManager:
DisableSaveOnCloseStudio
(
) →
(
)
For if you want to disable saving in studio for faster close time!
AddRemovingCallback
PlayerDataStoreManager:
AddRemovingCallback
(
callback:
function
--
May return a promise
) →
(
)
Adds a callback to be called before save on removal
RemovePlayerDataStore
Callable to allow manual GC so things can properly clean up. This can be used to pre-emptively cleanup players.
GetDataStore
PromiseAllSaves
Removes all player data stores, and returns a promise that resolves when all pending saves are saved.