DataStore Request Question

How would i run my code without getting this error?
image

-- Call DataStoreService and set an AllScopes parameter for later use
local dataService = game:GetService("DataStoreService")
local options = Instance.new("DataStoreOptions")
options.AllScopes = true
local DataStore = dataService:GetDataStore(game.ReplicatedStorage["Game Settings"].DataSave.Value, "", options)

-- This will be used to store the retrieved userIDs and Inventory
-- Each key will be a players userID, and the content of the key will be their inventory!
local dataDictionary = {}

-- Get all the stored keys under our Data Store
local listSuccess, pages = pcall(function()
	return DataStore:ListKeysAsync()
end)


print(pages:GetCurrentPage())

-- If the pcall succeeds without error, then this will run.
-- The loop will go on until all key values have been read through.
if listSuccess then
	while true do
		local items = pages:GetCurrentPage()
		for _, v in ipairs(items) do
			-- Take current key + its associated value and write it into the dictionary.
			local value
			local success, er = pcall(function()
				value = DataStore:GetAsync(v.KeyName)
			end)
			if success then
				dataDictionary[v.KeyName] = value
				print(v.KeyName, value)
			else
				print(er)
				warn("HIT THE RARE LIMIT")
				task.wait(10)
			end
		end
		if pages.IsFinished then
			break
		end
		pages:AdvanceToNextPageAsync()
	end
	
	print(dataDictionary)
end

Since that is a warning and not an error, the DataStore request will get added to the queue successfully and therefore your pcall won’t fail (e.g. this bit of code will only run if the :SetAsync itself was unsuccessful, for example due to an outage/API error!)

I would suggest waiting between each request individually to avoid the warning

1 Like

Thank you for the reply, i will actually try that, i have that in mind, but what came to my mind is this and expecting it to work.

else
				print(er)
				warn("HIT THE RARE LIMIT")
				task.wait(10)
			end

Yeah, the issue with that is it will only error once an actual error happens, in your case you just got a warning that you are nearing the limit but haven’t reached the limit yet

1 Like

image
Getting this error when re-running the code, i think probably because the key was still in Queue, how many seconds/minutes it will take, until the key is being removed in the queue?

According to the documentation here, it looks like the limit for GetAsync is 60 + numPlayers × 10 per minute. How many requests is your script sending?

I am using the commandbar, because i have something to do with all the players data

Hello dev!,
This type of topic has already been discussed and may be a solution for you

This happens because you are sending several requests without the server even being able to process the old one, so it leaves the new one you sent in a waiting queue and executes it after executing the last ones that are still being executed, the recommended thing would be to send a new one “Async” about 6 minutes since the last request!

1 Like