How would I get all the keys in a datastore?

I’m want to get a list of all the keys in a datastore, but I don’t know how I’m going to do it. I’ve tried using OrderedDatastores but I need to be able to store strings.

DataStore:ListKeysAsync()

1 Like

Use DataStore:ListKeysAsync() to get a list of keys, put this DataStore:ListKeysAsync("", 100) replace 100 with the amount you want to put

Hmm, ok. I tried it and it just printed out Instance, instead of the desired value of the key. Here’s my code:

local dss = game:GetService("DataStoreService")
local datastore = dss:GetDataStore("MyData")
local pages = datastore:ListKeysAsync("",100)
local currentPage = pages:GetCurrentPage()
for i, v in pairs(currentPage) do
    print(v)
end
1 Like

Hello, It returns a DataStoreKey instance. Therefore, if you want to get the actual key string of that DataStoreKey use print(v.KeyName) instead

DataStoreKey | Documentation - Roblox Creator Hub

2 Likes