An issue with ListKeysAsync while trying to recollect the keys

So, basicaly ive been trying to get all the keys from my datastore, I wanna retrieve them and convert the keys into a JSON, however, when I try and wait for the keys to be retrieved, after a few minutes this appears in the output:

I tried making that if the throttle happens error happens, it will wait an additional 30 seconds so the request can chill, but after the first time the error pops in, it keeps appearing after a few times:

If anybody knows how to fix this, or knows an alternate way to do what Im trying to, please let me know :pray: , Thanks.

  • heres the lines of code:
local HttpService = game:GetService("HttpService")
local DataStoreService = game:GetService("DataStoreService")

local TheDataStore = DataStoreService:GetDataStore("mydatastorehereignorehaha")

local AllDataStoreKeys = {}
local startTime = tick()

local Success, Pages = pcall(function()
	return TheDataStore:ListKeysAsync()
end)

if not Success then
	warn("Failed to list keys: " .. tostring(Pages))
	return
end
local pgc = 0
while task.wait() do
	local Items = Pages:GetCurrentPage()

	for _, Data in ipairs(Items) do
		table.insert(AllDataStoreKeys, Data.KeyName)

		if tick() - startTime >= 1 then
			
			print("PROGRESS: " .. #AllDataStoreKeys .. " KEYS")
			
			startTime = tick()
		end
	end
	
	pgc = pgc + 1
	print("pgc: ", pgc)

	task.wait(3)

	local success, err = pcall(function()
		Pages:AdvanceToNextPageAsync()
	end)

	if not success then
		warn("30 secs CD" .. tostring(err))
		task.wait(30.5)
	else
		--// finished
		if Pages.IsFinished then break end
	end
end
local JSON = HttpService:JSONEncode(AllDataStoreKeys)

print(JSON)
2 Likes

The “request was throttled” error usually occurs when you exceed the limits for operations like ListKeysAsync(), not fire too many in a short time. So it could be the way you’re retrieving it. I’m personally not too sure how to solve it but this is my advice in the right direction

1 Like

I see, im still trying to find a way to make this not happen at all, even if i give it a few minutes rest, it still come backs even earlier than the first time, thanks for answering tho