How do I put update:Async into a pcall?

So I have a script that uses UpdateAsync.
How would I put it into a pcall with succes and the errormessage?
That way I can tell if there is an error.

local function saveData(player)
	local tag = player.UserId..'_profile'

	local profile = player.Profile
	
	-- lets detect if there was no error
	if not player:FindFirstChild('Failed') then
		print('No error, updating data')
		
		local currentData = {
			gems = profile.Gems.Value,
		}
		
		profileStore:UpdateAsync(tag, function(pastData)
			print(pastData)
			return currentData
		end)
		
		
		
	else
		print('Error. We are not going to update there data')
	end
end

Here’s the parameter format for pcall:

Success, Result = pcall(Function, ...)
--All parameters after the first one are given to the Function

And here’s what the colon operator means:

--these two are the same
foo:bar(1, 2, 3)
foo.bar(foo, 1, 2, 3)

And wrapped in pcall:

pcall(foo.bar, foo, 1, 2, 3)

Using these information:

local success, result = pcall(profileStore.UpdateAsync, profileStore, tag, function(pastData)
  print(pastData)
  return currentData
end)
2 Likes