Hello I would like to know how could I Print every key from a datastore that starts with “Player_”
Thank you!
Hello I would like to know how could I Print every key from a datastore that starts with “Player_”
Thank you!
my bad I clicked the wrong channel
my idea may be bad but you could make an extra datastore that only has the keys and number like 1 2 3 4 5 6 7 etc.
with all the keys that you want to store in the list (may be really bad)
dang I’ve been coding for 2 years now and I’m still learning so many things XD
You could use the ListKeysAsync method on your datastore, and then iterate through the Pages instance.
Here’s a code example:
local DataStore = game:GetService("DataStoreService"):GetDataStore("YourDataStoreName") --Get the datastore
local PREFIX = "Player_"
local AMOUNT_OF_KEYS = 50 --Amount of keys you'd like to get/print.
local keys --Placeholder variable for our keys pages
local success, err = pcall(function() --In case the retrieval request fails, we should handle the error.
keys = DataStore:ListKeysAsync(PREFIX,AMOUNT_OF_KEYS) -- Retrieve the keys
end)
if(success and keys)then
while not keys.IsFinished do --While there are still pages:
task.wait()
local keysInPage = keys:GetCurrentPage() --Get the array of keys from the current page
for _, keyObject: DataStoreKey in pairs(keysInPage) do --Iterate through all the keys in the page
print(keyObject.KeyName) --Print the key
end
keys:AdvanceToNextPageAsync() --Advance to the next page of keys
end
elseif(err) then --If there's an error, and not just empty keys
warn(err) --Print the error as a warning
end
Imma try this right now! Thank for you helping me