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

Datastore:SetAsync() And Datastore:UpdateAsync() stops the script sometimes?

Asked by 4 years ago

Most of the time when I save the players data:

game.Players.PlayerRemoving:Connect(function(plr)
    print("player leaving")
    local foodVal = plr.leaderstats.Food.Value
    local totalfoodVal = plr.leaderstats["Total Food"].Value
    --save
    print("loaded values to save")
    local tries = 0 
    local success,err
    repeat
        print("loop")
        tries = tries + 1
        print("about to pcall")
        success,err = pcall(function()
            print("in pcall")
            totalFoodDs:UpdateAsync(plr.UserId,function()
                print("in the update function")
                return totalfoodVal
            end)
            print("set")
        end)
        print("pcalled")
        if not success then wait(1) print("waiting cus fail") end
    until tries == 3 or success
    if not success then
        warn("Failed To SAVE Total Food Data! UserId: "..plr.UserId.." err: "..err )
    end
end)

It just prints:

player leaving
loaded values to save
loop
about to pcall
in pcall

But other times it prints:

player leaving
loaded values to save
loop
about to pcall
in pcall
in the update function
set
pcalled

Answer this question