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

Datastore only loads/saves the tools I have sometimes?

Asked by 4 years ago
local service = game:GetService("DataStoreService")
local datastore = service:GetDataStore("lolaaaa1uh9")
local toolstosave = { }

game.Players.PlayerAdded:Connect(function(Player)
    if datastore:GetAsync(Player.userId) then
        for i, v in pairs(datastore:GetAsync(Player.userId)) do
            print(v)
        end
    end
end)



game.Players.PlayerRemoving:Connect(function(Player)
    local toolstosave = { }
    for i, v in pairs(Player.Backpack:GetChildren()) do
        table.insert(toolstosave, v.Name)
    end
    datastore:SetAsync(Player.userId, toolstosave)
end)

Sometimes, it does not print anything when I join, even though I left with tools. Any fix?

0
Seems to me like your code crashes, I have no idea as to why this is happening, but maybe experiment with a wait function possibly before the tools load in. BryanFehr 133 — 4y
0
All datastore calls are able to error. hiimgoodpack 2009 — 4y

Answer this question