IncrementAsync overflows when the delta is >= 2^31

local d=game:GetService'DataStoreService':GetDataStore'test'
d:SetAsync('x',0)

d:IncrementAsync('x',2^31)

print(d:GetAsync'x',2^31,-2^31)

This will output the value at key x to be -2^31 when it should be 2^31 instead

The best workaround I can think of right now is to use UpdateAsync

d:UpdateAsync('x',function(old)
	return old+2^31
end)

I’m confused. Do DataStores use 64 bits? I thought they used 32, which would explain why this happens. Does it not happen when you try to set it directly to 2^31?

I think DataStores store numbers as doubles like lua

So you can store up to 2^53 without losing integer precision:

local d=game:GetService'DataStoreService':GetDataStore'test'

d:SetAsync('x',2^53)
print(d:GetAsync'x'-2^53)--0

d:SetAsync('x',2^53-1)
print(d:GetAsync'x'-2^53)-- -1

d:SetAsync('x',2^31)
print(d:GetAsync'x'-2^31)-- 0