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
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