#HELP datastore

4 messages · Page 1 of 1 (latest)

tardy musk
empty mountain
#

The main error in the provided code seems to be a typo in the PlayerRemoving event handler. Here's the corrected version of that part of the code:

game.Players.PlayerRemoving:Connect(function(player)
    local Stats = player:WaitForChild("leaderstats")
    local values = {}
    
    for i, v in pairs(Stats:GetChildren()) do  -- Change "player.Stats" to "Stats"
        table.insert(values, v.Value)
    end
    
    local playerID = player.UserId
    local success, error = pcall(function()
        datastore:SetAsync(playerID, values)
        print(values)
    end)
    
    if not success then
        warn(error)
    end
end)

I noticed that in the loop where you're collecting the values from the leaderstats folder, you were using player.Stats instead of the correct variable name Stats. This should fix the issue and ensure that the script works as intended.

tardy musk
#

yo

#

thanks man