When you call this:
print(datastore:UpdateAsync("TestKey", function(oldValue) (...) end))
No matter what the code in the transformFunction is, the UpdateAsync call should always return the value stored at that key at that moment in time, so the latest value of the key should be printed.
However, if the code inside the transformFunction returns nil, this indicates that the update should be cancelled, which is indeed what happens, but the UpdateAsync call also returns nil! This would falsely indicate that the current value of the key is nil, which is not the case.
How to reproduce:
- Publish a baseplate to a game with Studio API access.
- Run the following code in the command bar:
data = game:GetService("DataStoreService"):GetOrderedDataStore("Test")
data:SetAsync("TestKey", 42)
local retValue = data:UpdateAsync("TestKey", function() return nil end)
print("return value of UpdateAsync: " .. tostring(retValue))
local storedValue = data:GetAsync("TestKey")
print("current value of TestKey: " .. tostring(storedValue))
- Observe output.
Observed behavior:
return value of UpdateAsync: nil
current value of TestKey: 42
UpdateAsync should return the “value of the entry in the data store with the given key”, but instead returns nil, while the key wasn’t updated to nil, it’s still 42! (as it should be, the return value of UpdateAsync is just wrong here)
Expected behavior:
return value of UpdateAsync: 42
current value of TestKey: 42