DataStore:UpdateAsync() doesn't return value if nothing is changed

Edit: Can a staff member or whatever make it more clear on the dev forum about this (i spent the last 20 minutes trying to debug and this was the root cause)

I just want to check if this is expected behaviour.

local new = DataStore:UpdateAsync(key, function(old)
  print(old) -- 5
end)

print(new) -- nil

I was kinda expecting it to return the value whether it was changed or not

please someone clear this up

a quick work around if it is

local origin

local new = DataStore:UpdateAsync(key, function(old)
  origin = old
  print(old) -- 5
end)

print(new) -- nil
print(origin) -- 5

local value = new or origin

print( value) -- 5

If the callback function doesn’t return a value the existing value is preserved.

1 Like