Datastore: Too Many Requests

I have this module which allows users to create clans and invite people to those clans.

Sometimes, the script returns


'DatastoreService: Too many Reqeusts, try again later. API: ListKeysAsync, Data Store: TeamDataStoreTest…

I don’t know why it does that?

Here is the module:

local module = {}

local TeamDataStore = game:GetService("DataStoreService"):GetDataStore("TeamDataStoreTest46")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteFunctions = ReplicatedStorage:WaitForChild("Functions")

local DataFetcher = require(ReplicatedStorage:WaitForChild("Modules"):WaitForChild("DataFetcher"))

local function getTeamIdOfLeader(leaderPlayer)
	local allTeams = DataFetcher.getAllData()

	for teamId, teamData in pairs(allTeams) do
		if teamData['Manager'] == leaderPlayer.UserId then
			return teamData
		end
	end

	return nil
end

function module.getLeadersTeam(leaderPlayer)
	local allTeams = DataFetcher.getAllData()


	for teamId, teamData in pairs(allTeams) do
		if teamData["Manager"] == leaderPlayer.UserId then
			return teamData
		end

	end

	return nil
end

function module.isPlayerInTeam(player)
	local playerUserId = player.UserId
	local allTeams = DataFetcher.getAllData()

	for teamId, teamData in pairs(allTeams) do
			if table.find(teamData["Members"], player.UserId) then
				return teamData
			end
	end

	return nil
end

local function isPlayerInTeam(player)
	local playerUserId = player.UserId
	local allTeams = DataFetcher.getAllData()

	for teamId, teamData in pairs(allTeams) do
		if teamData.Members then
			for i,v in pairs(teamData.Members) do
				print(v)
			end
			
			if table.find(teamData["Members"], player.UserId) then
				return {true, teamData}
			end
		end
	end

	return false
end

function module.invitePlayer(player, invited)
	local invitedplayer = game.Players:GetUserIdFromNameAsync(invited.Name)
	local result = RemoteFunctions.TeamInviter:InvokeClient(invited, player)

	if result == true then
		print("Accepted")
		if isPlayerInTeam(invited) == false then
			print("Not in a tean")
			local TeamData = getTeamIdOfLeader(player)
			if TeamData then
				print("Found team!")
				table.insert(TeamData.Members, invited.UserId)
				TeamDataStore:SetAsync(getTeamIdOfLeader(player), TeamData)
			end
		end
	else
		print(result)
	end
end



function module.createTeam(teamName,teamDescription,teamLogo,managerPlayer)
	local newTeam = {
		Name = teamName,
		Descripton = 'Welcome to '..teamName..', this is a great TBS team which you should consider joining, We have a great community.',
		TeamLogo = "15904336970",
		Manager = managerPlayer.UserId,
		Members = {managerPlayer.UserId},
		Sponsor = "No Sponsor"
	}

	newTeam.Descripton = teamDescription
	newTeam.TeamLogo = teamLogo

	local teamId = os.time() .. "_" .. tostring(math.random(100000, 999999))

	while TeamDataStore:GetAsync(teamId) do
		teamId = os.time() .. "_" .. tostring(math.random(100000, 999999))
	end

	TeamDataStore:SetAsync(teamId, newTeam)

	return {teamId, newTeam}
end


return module

And the module which uses :ListAllKeysAsync()

local module = {}

function module.getAllData()
	local dataService = game:GetService("DataStoreService")
	local options = Instance.new("DataStoreOptions")
	options.AllScopes = true
	local DataStore = dataService:GetDataStore("TeamDataStoreTest46", "", options)

	local dataDictionary = {}


	local listSuccess, pages = pcall(function()
		return DataStore:ListKeysAsync()
	end)


	if listSuccess then
		while true do
			local items = pages:GetCurrentPage()
			for _, v in ipairs(items) do
				local value = DataStore:GetAsync(v.KeyName)
				dataDictionary[v.KeyName] = value
			end
			if pages.IsFinished then
				break
			end
			pages:AdvanceToNextPageAsync()
			wait(0.1)
		end
	end
	
	return dataDictionary
end

return module

Please help me to fix this

I am having the same problem. Have you fixed it?

Nope, sorry I havent
…eteihiesz