So using data stores is it better to keep a long list and put it in a single datastore or get multiple datastores for stats.
COMMUNITY QUESTION
Best way for data saves?
1 answer
It depends if you're willing to decode it or not (decoding is kinda hard, with things like string patterns). I believe you can save tables, if that helps. Here's an example:
local ds = game:GetService("DataStoreService"):GetDataStore("PlayerData")
game.Players.PlayerAdded:connect(function(p)
local data
local key = "user_" ..p.UserId
local success = pcall(function() data = ds:GetAsync("PlayerId") end)
if not success then -- checks to see if player is new
data = {["KOs"] = 0, ["WOs"] = 0}
end
setLeaderstatsToData(data) -- cause I can't be bothered writing a leaderstats script, and it'snot relevant
end
game.Players.PlayerRemoving:connect(function(p)
local key = "user_" ..p.UserId
local data = setDataToLeaderstats(p.leaderstats)
if not data then -- sees if the data exist
return
end
ds:SetAsync(key,data) -- or UpdateAsync()
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
thanks