Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[FIXED]Datastore update async not running?

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

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

4 comments

0

yeah i tried doing warn(err) but success is true

0

im using updateasync and my problem is updateasync not the status or the success its the function not calling

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.

0

it doesn't even run anything inside updateasync doesn't work

This discussion is preserved as it was. New answers, comments, and votes are closed.