Double is not allowed on Datastore?

Hello! I’m currently scripting a rather simple datastore…
Could someone please help me out with this error? It only happens when a user leaves the game… This error message is very useless.

The script for my saving is

function onPlayerLeave(plr)
	print('save')
	local playerssize = plr.leaderstats:FindFirstChild("Size")
	local thisistherealvalue = plr:FindFirstChild("ActualSize")
	SavedSize:SetAsync(plr.userId, playerssize.Value)
	print(thisistherealvalue.Value)
	actualSize:SetAsync(plr.userId.."actualsize", thisistherealvalue.Value)
end
2 Likes

It looks like you are trying to save a double (decimal) into an ordered data store; you can only save integers (whole numbers) in an ordered data store.

If your decimals only have a certain level of precision (4 decimals points for example), you can multiply the value you save by 10,000 and divide it by 10,00 when you retrieve it.

21 Likes

a double is a number that’s not an integer

Thank you, solution has been recieved!!

When I first jumped over to learning Java I thought it was dumb that there we different number types. It really tripped me up there in the beginning.

Don’t even get me started on the headache I got from figuring out that arrays don’t start at 1.

2 Likes

A bit off topic, but does anybody know why you can’t save doubles in data stores? They’re JSON serializable.

Assuming this is an ordered DataStore as @TheNickmaster21 said,

it could possibly be because some algorithms for inserting into a sorted integer list are faster than lg n average

And since doubles aren’t integers, this might force Roblox to have to use something else that is potentially slower

If this is an unordered DS then idk you should probably be able to save

I’m not very taught on the subject a part from the big ones, but I know of no sorting algorithms that have a different time complexity with ints and doubles.

The only one I know of (I don’t know much about this) is the van emde boas tree which is O(lg lg m) average insertion where m is the size of the universe of possible keys

(tbh the extra lg factor - although technically makes constant time operations since its always O(lg lg [whatever the max int size is *2 bc signed]) - isnt even significant for pratical usage)

also these arent sorting algorithms, these are sorted datastructures

You make a good case, but I feel like they wouldn’t use that and instead use something more reasonable like QuickSort.

As for your last statement, you make a good point. No sorting algorithm needs to be done because sorting only takes place on insertion, which there are more efficient algorithms for.

Depending on how much resolution you need you can multiply by 2^n and round down while storing.
Then when retrieving divide by 2^n

Correct. For the use case of Ordered Datastores, which is typically writing one value at a time but retrieving sorted chunks (like top 100 scores), it only makes sense to store the data sorted. Inserting is always O(log N) with a binary search.

So can you weigh in on why doubles aren’t allowed?

I can understand why only one type is allowed, since you don’t want to have to do type conversions when comparing, but I don’t know why unsigned integer was chosen. I could guess that this is because direct comparisons for equality are always valid, whereas two floating-point computations that should come up with the same value don’t necessarily produce equal values. An integer sort is going to be stable and reproducible, and not subject to rounding issues if you slightly change how you calculate the values you store.

5 Likes

Doubles are probably fine for normal data stores. This is an ordered data store, where your solution doesn’t make sense.

1 Like

Thanks for this, I was trying to save an exact tick() to an ordered datastore. For anyone else wondering I also used math.floor to remove unnecessary decimal places.

math.floor(tick()*1000)