Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I get amount of entries in an ordered data store?

My goal here is to get the amount of entries in the ordered datastore, and from there add an entry with a number based off of the amount that it has already read (if that makes sense).

I am very new to ordered datastores, and I'm only just now learning it because I want to make a police database system where you can put in a player's name, and it will return their criminal record with 'arresting officer' 'arrest time' and 'arrest reason'. The code below is supposed to count the amount of entries in the datastore and add a new value based on the count, but it results in an error.

local arrestingOfficerDataStore = game:GetService("DataStoreService"):GetOrderedDataStore(suspect.Name.."_ArrestingOfficers")
local numberOfArrests
for i = 100,1,-1 do
    if arrestingOfficerDataStore:GetAsync(i) ~= nil then
	    numberOfArrests = i
	    print(i)
    end
end
arrestingOfficerDataStore:SetAsync(numberOfArrests+1,arrestingOfficer.Name)

I'm probably doing it all wrong, but I honestly don't know where to go from here. Youtube has a couple videos, and the roblox wiki isn't very helpful.

1 answer

If the datastore is stored as a table, you should just be able to access it like this:

datastore = your datastore:GetAsync(key) -- replace your datastore and key with your values
for i,v in pairs(datastore) do
		print(i)
end

This discussion is preserved as it was. New answers, comments, and votes are closed.