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 5 years ago
Edited 5 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

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

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

01game.Players.PlayerRemoving:Connect(function(pla)
02    local suc, err = pcall(function()
03        print('hi')--prints
04        skill:UpdateAsync(tostring(pla.UserId..key), function(oldval)
05            print('update')--doesn't print
06            if tonumber(oldval) == nil then print("it is nil and saved") return pla.leaderstats.Level.Value end
07            if pla.leaderstats.Level.Value >= oldval then
08                print('returned more')
09                return pla.leaderstats.Level.Value
10            else
11                print('less than save')
12                return oldval
13 
14            end
15        end)
16    end)
17end)

NO ERRORS

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 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.

01local status, errorString = pcall(function()
02    return datastore:SetAsync(key, value)
03end)
04 
05if status == false then -- this boolean will be false if an error happened in the pcall
06    warn(errorString) -- warn the error to output so you can read it without halting execution
07 
08else -- otherwise it all worked out without erroring, do what you need to here
09 
10end
0
yeah i tried doing warn(err) but success is true HappyTimIsHim 652 — 5y
0
im using updateasync and my problem is updateasync not the status or the success its the function not calling HappyTimIsHim 652 — 5y
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 — 5y
0
it doesn't even run anything inside updateasync doesn't work HappyTimIsHim 652 — 5y
Ad

Answer this question