UpdateAsync or SetAsync in this case?

I followed this tutorial : Datastore Beginner To Advanced to create a datastore script, but it seems that updateAsync isn’t necessary in my case, but I’m not sure. In fact, the values I save change very regularly, so there’s a 90% chance that when a save is made, at least one of the values in the table has changed, in which case the whole table will be replaced by the new values (i guess) (unless the player joins and leaves without playing). This leads me to the conclusion that a simple SetAsync would be more efficient in this case. I’d like to hear your opinion. Thanks for your help

1 Like

The Only time :UpdateAsync() would be less efficient than :SetAsync() is if you arent using it to check data, and are just saying return data, like this for example:

DataStore:UpdateAsync(Key, function(OldData)
    return Data 
end)
-- This is a pretty inefficient use of :UpdateAsync(), you are better off
-- using :SetAsync() instead.
2 Likes

Hi thanks for your answer, when i save the data that how i do :

			success = pcall(dataStore.UpdateAsync, dataStore, key, function()
					return {
						SessionLock = dontLeave and os.time() or nil,
						--Lot of value;
					}			
				end)
			until success

And when i load the data :

repeat task.wait(1)
		waitForRequestBudget()
		success = pcall(dataStore.UpdateAsync, dataStore, key, function(oldData)
			oldData = oldData or default
			if oldData.SessionLock then
				if os.time() - oldData.SessionLock < 1800 then
					shouldWait = true
				else
					oldData.SessionLock = os.time()
					data = oldData
					return data
				end
			else
				oldData.SessionLock = os.time()
				data = oldData
				return data
			end
		end)
		if shouldWait then
			task.wait(5)
			shouldWait = false
		end
	until (success and data) or not Players:FindFirstChild(name)

Could you explain me what the point of using update async in that case i don’t need the old data as in 90% of time , the value gonna change and the new data overwrite the old one ?

2 Likes

Any help is still apprecied , thank you =)

Hi again , sorry for beggin for help lol, if any of you have an answer i would be happy to hear it =) Any help is apprecied