79613889

Date: 2025-05-09 10:06:52
Score: 1.5
Natty:
Report link

The DataStoreKeyPages interface returned by ListKeysAsync is not a table or element you can directly iterate over, but rather an object for getting pages of arrays to iterate over. Take a look at the documentation for DataStoreKeyPages. Here's an example to iterate over all the keys:

local keyPages = lvlStore:ListKeysAsync()
while not keyPages.IsFinished do
    for i,v in keyPages:GetCurrentPage() do
        -- Your stuff here
    end
    keyPages:AdvanceToNextPageAsync()
end

You might be interested in increase the pageSize argument of ListKeysAsync to reduce the amount of requests and async calls you have to make to iterate over all keys.

Beware - there's limits on how many times you can ask to iterate over the keys, and iterating over every key on a DataStore is an expensive operation. It's fine with a limited amount of keys - but doing it over and over for a large datastore will easily make you reach the limits. Have you thought of doing this someway else (possibly, store the list of keys in a DataStore value itself)?

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (0.5):
Posted by: Aimarekin