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

[FIXED]Datastore update async not running?

Asked by 4 years ago
Edited 4 years ago

I used to use update async and recently I started developing a new game and I'm having trouble with the update async. These are the variables

local gui = game.ServerStorage.Overhead--ignore its useless
local ds = game:GetService("DataStoreService")
local skill = ds:GetDataStore("Levels")
local key = "-level"

Then this is the part of the script that doesn't work

game.Players.PlayerRemoving:Connect(function(pla)
    local suc, err = pcall(function()
        print('hi')--prints
        skill:UpdateAsync(tostring(pla.UserId..key), function(oldval)
            print('update')--doesn't print
            if tonumber(oldval) == nil then print("it is nil and saved") return pla.leaderstats.Level.Value end
            if pla.leaderstats.Level.Value >= oldval then
                print('returned more')
                return pla.leaderstats.Level.Value
            else
                print('less than save')
                return oldval

            end 
        end)
    end)
end)

NO ERRORS

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

You are calling UpdateAsync inside of a pcall. pcall is short for protected call, essentially meaning any error that kicks will not cause Lua to error, but instead be returned as strings. This is to let you handle those errors within Lua.

local status, errorString = pcall(function()
    return datastore:SetAsync(key, value)
end)

if status == false then -- this boolean will be false if an error happened in the pcall
    warn(errorString) -- warn the error to output so you can read it without halting execution

else -- otherwise it all worked out without erroring, do what you need to here

end
0
yeah i tried doing warn(err) but success is true HappyTimIsHim 652 — 4y
0
im using updateasync and my problem is updateasync not the status or the success its the function not calling HappyTimIsHim 652 — 4y
0
So that would mean UpdateAsync is running, it's your saved value that is not what you expect it to be. Make sure Level.Value is correct and that it's not hitting the oldValue condition. InfinityDesign 280 — 4y
0
it doesn't even run anything inside updateasync doesn't work HappyTimIsHim 652 — 4y
Ad

Answer this question