Im currently working on an AdminSystem.
I want the game to get all saved Admins and Supporters, which have been added to the game. But for some reason, its not working. The loop is working but the print command is giving nil (And yes, I saved already Data in the Datastore). I found this code example but I cant just make it work. Its a script inside ServerScriptService. As DataStoreKey, I am using the players Name.
local DataStoreService = game:GetService("DataStoreService")
local AdminStore = DataStoreService:GetDataStore("AdminList1")
local succes, pages = pcall(function()
return AdminStore:ListKeysAsync()
end)
print(succes, pages)
if succes then
while true do
local items = pages:GetCurrentPage()
for i, v in pairs(items) do
local value = AdminStore:GetAsync(v)
print(value)
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
end
end
local DataStoreService = game:GetService("DataStoreService")
local AdminStore = DataStoreService:GetDataStore("AdminList1")
local success, pages = pcall(function()
return AdminStore:ListKeysAsync()
end)
print(succes, pages)
while success and not pages.IsFinished do
local items = pages:GetCurrentPage()
for _, v in items do
local s, value = pcall(AdminStore.GetAsync, v)
print(value)
end
pages:AdvanceToNextPageAsync()
end
Donāt know if this did anything but you could give it a go.
print(succes, pages)
while succes and not pages.IsFinished do
local items = pages:GetCurrentPage()
for _, v in items do
local s, value = pcall(function()
return AdminStore:GetAsync(v)
end)
print(value)
end
pages:AdvanceToNextPageAsync()
end
I tried it now with that loop based on yours, but your pcall function wouldnt work like that, but I still get nil for the value and ātrue, instanceā for the succes,pages print.
local DataStoreService = game:GetService("DataStoreService")
local AdminStore = DataStoreService:GetDataStore("AdminList1")
local success, pages = pcall(AdminStore.ListKeysAsync, AdminStore)
if success then
while true do
local items = pages:GetCurrentPage()
for rank, data in items do
print(data.Value)
end
if pages.IsFinished then break end
pages:AdvanceToNextPageAsync()
end
end
The items table has the rank as the key and the DataStore data as the value
Edit: Alternatively data.value might work if data.Value results in an error
Edit 2: @Faustollol Please ignore what I wrote above this, because I found the solution:
local DataStoreService = game:GetService("DataStoreService")
local AdminStore = DataStoreService:GetDataStore("AdminList1")
local success, pages = pcall(AdminStore.ListKeysAsync, AdminStore)
if success then
while true do
local items = pages:GetCurrentPage()
for index, dataStoreKey in items do
local success, value = pcall(AdminStore.GetAsync, AdminStore, dataStoreKey.KeyName)
if success then print(value) end
end
if pages.IsFinished then break end
pages:AdvanceToNextPageAsync()
end
end
The items table actually has a DataStoreKey Instance as a value that has the property KeyName which represents the DataStoreās key. The problem you were getting was because you were using DataStoreKey directly instead of the KeyName property