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

Is this the right way to wrap updateasync around a pcall?

Since Setasync dosen't have a end and its like weird

I got confused cause with setasync

you can just wrap it around simply

but I don't think I did my UpdateAsync right

The S prints true and E prints a table but I was wondering what that table was and if I did this right

local S,E = pcall(function()
	
	local UpdateAsync = DataStoreOfStats:UpdateAsync(Player.UserId,function(OldValue)
		
	return OldValue
		
end)
		
	return UpdateAsync
	
end)

print(S,E)

1 answer

✓ Accepted answer

You don't need to set the function to a variable. The pcall wraps whatever is inside of it and since UpdateAsync returns a result if it works, Success will return true or false based on whether it saved correctly.

local Success, Result = pcall(function()
	DataStoreOfStats:UpdateAsync(Player.UserId, function(OldValue)
		return OldValue and OldValue + 1 or 1
	end)
end)

print(Success and "Saved" or 'Failed', Result)

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