Hey. I am making a Data Store for my game right now. I am using a new data store for every player but I want to know if I should put all of the players data in the same data store or make a specific data store for coins and xp. Thanks for the help!
You can use a (dictionary) table to store both coins and xp, which is quite convenient. To answer your question, I believe having one datastore is enough to store all the information you need.
local DSS = game:GetService("DatastoreService")
local Store = DSS:GetDataStore("YourStore")
local stats = {
Coins = 0,
XP = 0
}
game.Players.PlayerAdded:Connect(function(plr)
local key = "id_" .. plr.UserId
local data = Store:GetAsync(key) or stats -- if there is no save file, it sets the stats table as the player's table
end)
game.Players.PlayerRemoving:Connect(function(plr)
Store:SetAsync(key, data)
end)
Use this as a guideline. This code is not sufficient to be used in a game.
2 Likes
You can put an individual player’s data in one datastore, there’s more than enough (260k char limit) for values. You can use tables to store them. Also as for @AbiZinho’s guideline it’d be better to use UpdateAsync when saving player data.
1 Like
I don’t think you understand how UpdateAsync works, so here’s a link to its wiki page.
It takes a function as its second parameter, not a table/whatever “data” is.
1 Like