Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Best way for data saves?

Asked by 8 years ago

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.

1 answer

Log in to vote
0
Answered by 8 years ago

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
0
thanks QuantumToast 261 — 8y
Ad

Answer this question