How could I get all users [keys] from a datastore? I’m trying to make a script that gets all keys, clones a frame, and puts the data from the keys into that frame.
I’ve looked at past posts and followed what they said, but they didn’t seem to work.
Here is my code:
--//Datastores
local RouteDatastores = DataStoreService:GetDataStore("Routes")
--//Webhook
local webhookURL = ""
function AddCurrentRoutes(player)
-- Assuming ReplicatedStorage has a structure like ReplicatedStorage.Assets.Template
local Template = ReplicatedStorage.Assets.Template
local PlayerGui = player:WaitForChild("PlayerGui")
local RoutesGui = PlayerGui:WaitForChild("ScreenGui"):WaitForChild("Routes")
local List = RoutesGui.RoutesList
-- Use ListKeys instead of ListKeysAsync to fetch keys
local success, keys = pcall(function()
local pages = RouteDatastores:ListKeysAsync("", 30)
return pages:GetCurrentPage()
end)
if not success then
warn("Failed to fetch data from the datastore")
return
end
for _, entry in pairs(keys) do
local Clone = Template:Clone()
local RouteData = RouteDatastores:GetAsync(entry)
if RouteData then
Clone.Parent = List
Clone.Host.Value = tostring(RouteData.Host)
Clone.Time.Value = tostring(RouteData.Time)
Clone.Code.Value = tonumber(RouteData.Code)
else
warn("Failed to retrieve data for route: " .. entry)
end
end
end