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
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.
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.
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.
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.
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.