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.
If the datastore is stored as a table, you should just be able to access it like this:
```Lua datastore = your datastore:GetAsync(key) -- replace your datastore and key with your values for i,v in pairs(datastore) do print(i) end