ListKeysAsync
This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts.
For thread safety, this property is not safe to read in an unsynchronized thread.
This function returns a DataStoreKeyPages
object for enumerating through keys of a data store. It accepts an optional prefix
parameter to only locate keys whose names start with the provided prefix.
If DataStoreOptions/AllScopes
was set to true when accessing the data store through DataStoreService/GetDataStore
, keys will be returned with all scopes as prefixes.
See Also
Articles/Data store|Data Stores
, an in-depth guide on data structure, management, error handling, etc.
Parameters
Name | Type | Default | Description |
---|---|---|---|
|
(Optional) Prefix to use for locating keys. |
||
0
|
(Optional) Number of items to be returned in each page. |
Returns
Return Type | Summary |
---|---|
A |
Code Samples
List Keys by Prefix
local DataStoreService = game:GetService("DataStoreService") local options = Instance.new("DataStoreOptions") options.AllScopes = true local buildingsStore = DataStoreService:GetDataStore("BuildingTypes", "", options) -- Search keys by prefix "house" local listSuccess, pages = pcall(function() return buildingsStore:ListKeysAsync("house") end) if listSuccess then while true do local items = pages:GetCurrentPage() for _, v in ipairs(items) do local value = buildingsStore:GetAsync(v.KeyName) print("Key: ", v.KeyName, "Value: ", value) end if pages.IsFinished then break end pages:AdvanceToNextPageAsync() end end