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

SetAsync not printing success or error message?

Asked by 3 years ago

I have been messing around with my save and load data script but it seems like the SetAsync doesn't want to work. The save data does not want to print a success or an error message after setasync is called.

local DataStoreService = game:GetService("DataStoreService")
local CashStore = DataStoreService:GetDataStore("Cash") 
local KillsStore = DataStoreService:GetDataStore("Kills")

Not sure if this will help but here are the datastore declarations.

game.Players.PlayerRemoving:Connect(function(player)
    local playerKey = "Player_" .. player.UserId
    local myCash = player.leaderstats.Cash.Value
    local myKills = player.leaderstats.Kills.Value
    print("player has "..myCash.." Cash")
    print("Player has "..myKills.." Kills")

    local success, err = pcall(function()
        myCash = CashStore:SetAsync(playerKey,myCash)
        myKills = KillsStore:SetAsync(playerKey,myKills)
    end)

        if success then
        print("Saved with "..myCash.." Cash")
        print("Saved with "..myKills.." Kills")
        else
            print("error")
            warn(err)
    end
end)

The function will print the first two lines it is asked to print but after the SetAsync there is no message at all. When I load back in my cash and kills are back to where they started.

Answer this question