Can you pass UpdateAsync function argument another parameter?

I’m trying to use UpdateAsync to update a datastore which the same key/entry can be updated cross server. However, to determine new value, I need more data then just the oldValue like they show in the UpdateAsync documentation page. So instead of something like this:

local success, err = pcall(function()
	pointsDataStore:UpdateAsync(playerKey, function(oldValue)
		local newValue = oldValue or 0
		newValue = newValue + 50
		return newValue
	end)
end)

I would like to do something like this:

local success, err = pcall(function()
	pointsDataStore:UpdateAsync(playerKey, function(oldValue, multiplier)
		local newValue = oldValue or 0
		newValue = newValue + 50 * multiplier
		return newValue
	end)
end)

Is that possible?

No, just have multiplier defined in a separate scope. Also, why would you ditch anything that happened in the session and save what they already had saved + 50 * multiplier?

1 Like

if i define it in an outside scope will i have access to it inside the passed function?

Yes, just like how you can access pointsDataStore inside the pcalled function.

1 Like