How do I get the amount of values in an OrderedDatastore?

I am currently trying to make a database system where an officer can input a player name, and it will return that player’s criminal record. I was tinkering around with the code from my previous question and I found out that it does get more than 8 values, but the way I was saving the values was not working properly (if that makes sense).
This is a pretty straight-forward and general question but how do I get the amount of values in an ordered datastore in order to properly save a value?

I’ve tried

for name, value in pairs(dataPages) do
    print("a value")
end

and

for i = #dataPages,1,-1 do
	print(i)
end

and originally

local dataAsync = recordDataStore:GetSortedAsync(true,100)
local dataPages = dataAsync:GetCurrentPage()
recordDataStore:SetAsync("Value",#dataPages+1)

but all of these don’t seem to work properly. I’ve tried searching everywhere and even asked other websites with no help.

You can’t, you can only advance to the next page with :AdvanceToNextPageAsync()

You can’t do #dataAsync:GetCurrentPage() to get the total amount of Data for that key.

OrderedDataStore

DataStorePages

Then how would I save a value with a key that isn’t in use? This is my first time using OrderedDatastores

You wouldn’t want to use OrderedDatastore for that kind of usage, it is specifically for Ordering Data and not meant to be used in another way.

What you want to use is DataStore

DataStoreService


Luckily there are so many resources out there about DataStore, these are my favorites!

Articles | Saving-Player-Data

1 Like