New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Datastore only loads/saves the tools I have sometimes?

Asked by 3 months 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 81 — 3mo
0
All datastore calls are able to error. hiimgoodpack 1865 — 3mo

Answer this question