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

How would I finish this DataStore load?

Asked by 8 years ago

I'm having a bit of trouble understanding what I should do for loading the Values from the Datastore table to the actual IntValues in the players leaderstats.

I'm really new to Datastores so if you could please break it down for me I would really appreciate it!

local ds = game:GetService("DataStoreService"):GetDataStore("PlayerStats2")

local getStats = Instance.new("BindableFunction")
getStats.Name = "getStats"
getStats.Parent = script

function saveStats(player)
    local statz = player:FindFirstChild("leaderstats") 
    local stats = statz:GetChildren()
    if stats then
        local statsTab = {}
        for i,v in pairs(stats) do
            statsTab[v.Name] = v.Value
        end

        ds:SetAsync(tostring(player.UserId), statsTab)
    end
end

function getStats(player)
    return ds:GetAsync(tostring(player.UserId)) or {}  
end
                                  --**What would I do here to have the datastore load the saved Values**?
while true do
    wait(60)
    for i,v in pairs(game.Players:GetPlayers()) do
        saveStats(v)
    end
end


game.Players.PlayerRemoving:connect(saveStats)
getStats.OnInvoke = getStats
0
Set the leaderstats to the player.UserID's stats. iFlusters 355 — 8y
0
How would I set the leaderstats to the player.UserID's stats? PsychonautX 15 — 8y

Answer this question