UserHasBadgeAsync: Parsed invalid JSON: "Too many requests"

Hi, I am trying to fix an index for a “find the” game. but I keep running into this error and I’ve never edited the script before. if anyone wants to take a look and help me I will greatly appreciate it :pray: (error is in line 64)

local BadgeService = game:GetService("BadgeService")
local player = script.Parent.Parent.Parent.Parent.Parent
local UserId = player.UserId

local owned = script.Owned
local total = script.Total

script.Owned:GetPropertyChangedSignal("Value"):Connect(function()
	script.Parent.Parent.Amount.Text = tostring(owned.Value).."/"..tostring(total.Value)
end)

for _,flag in pairs (workspace.Flags:GetChildren()) do
	total.Value =  total.Value +1
	local template = game.ServerStorage.FlagTemplate:Clone()
	local BadgeId = flag.BadgeID.Value
	
	template.Name = flag.Name
	template.FlagName.Text = flag.Name
	template.Parent = script.Parent.Frame
	template.ImageLabel.Image = flag.Decal.Texture
	template.Description.Value = flag.Description.Value
	
	if flag.Difficulty.Value == "Easy" then
		template.Difficulty.Text = flag.Difficulty.Value
		template.LayoutOrder = -9
		template.Difficulty.TextColor3 = Color3.fromRGB(31, 128, 29)
	elseif flag.Difficulty.Value == "Medium" then
		template.Difficulty.Text = flag.Difficulty.Value
		template.LayoutOrder = -8
		template.Difficulty.TextColor3 = Color3.fromRGB(248, 207, 109)
	elseif flag.Difficulty.Value == "Hard" then
		template.Difficulty.Text = flag.Difficulty.Value
		template.LayoutOrder = -7
		template.Difficulty.TextColor3 = Color3.fromRGB(196, 40, 28)
	elseif flag.Difficulty.Value == "Very Hard" then
		template.Difficulty.Text = flag.Difficulty.Value
		template.LayoutOrder = -6
		template.Difficulty.TextColor3 = Color3.fromRGB(170, 0, 0)
	elseif flag.Difficulty.Value == "Insane" then
		template.Difficulty.Text = flag.Difficulty.Value
		template.LayoutOrder = -5
		template.Difficulty.TextColor3 = Color3.fromRGB(153, 0, 229)
	elseif flag.Difficulty.Value == "Extreme" then
		template.Difficulty.Text = flag.Difficulty.Value
		template.LayoutOrder = -4
		template.Difficulty.TextColor3 = Color3.fromRGB(0, 0, 141)
	elseif flag.Difficulty.Value == "Terrifying" then
		template.Difficulty.Text = flag.Difficulty.Value
		template.LayoutOrder = -3
		template.Difficulty.TextColor3 = Color3.fromRGB(74, 240, 255)	
	elseif flag.Difficulty.Value == "Catastrophic" then
		template.Difficulty.Text = flag.Difficulty.Value
		template.LayoutOrder = -2
		template.Difficulty.TextColor3 = Color3.fromRGB(0, 0, 0)
	elseif flag.Difficulty.Value == "😈" then
		template.Difficulty.Text = flag.Difficulty.Value
		template.LayoutOrder = -1
		template.Difficulty.TextColor3 = Color3.fromRGB(27, 42, 53)	
	end
	
	if BadgeId ~= 0 then
		coroutine.resume(coroutine.create(
			function()
				if BadgeService:UserHasBadgeAsync(UserId, BadgeId) then
					task.wait()
					template.BackgroundColor3 = Color3.fromRGB(0,255,0)
					owned.Value = owned.Value+1
				end
			end
			))
		script.Parent.Parent.Amount.Text = owned.Value.."/"..total.Value
	end
	script.Parent.Parent.Amount.Text = tostring(owned.Value).."/"..tostring(total.Value)
end

This means that you are too quick to check if the player has a badge. If I’m not mistaken, it’s 100 request in 1 minute. Try to limit your queries. If you tell me exactly how you use this function, then I can probably help you better.

basically, it checks if the player has the badge and changes the backround colour in the index, i followed a tutorial but the code just started breaking after adding more items to the index. me and my cousin have been trying to fix it but no success and I dont even under stand it at this point

There is also another script that basically adds an item to the index once you touch it and there was an error at line 20

local HumanoidRootPart = script.Parent:WaitForChild("HumanoidRootPart")
local Flags = game.Workspace:WaitForChild("Flags")
local BadgeService = game:GetService("BadgeService")

local player = game.Players.LocalPlayer
local UserId = player.UserId

deb = false

for i,v in pairs(script.Parent:GetChildren()) do
	if v:IsA("BasePart") then
		v.Touched:Connect(function(hit)
			if hit.Parent == workspace.Flags and deb == false then
				deb = true
				local plr = game.Players.LocalPlayer
				local hun = script.Parent:WaitForChild("Humanoid")
				local Gui = game.Players.LocalPlayer:WaitForChild("PlayerGui"):WaitForChild("CollectGui").Text
				local badge = hit.BadgeID.Value
				
				if badge ~= nil and badge ~= 0 and BadgeService:UserHasBadgeAsync(plr.UserId, badge) then
					task.wait()
					--Gui.Parent.Enabled = true
					--Gui.Parent.Difficulty.Visible = false
					--Gui.Parent.Text.Visible = false
					--Gui.Parent.Label.Visible = false
					--Gui.Parent.AlreadyFound.Visible = true
					
					game.StarterGui:SetCore("SendNotification", {
						Title = hit.Name,
						Text = "Already Found!",
						Icon = hit.Decal.Texture
					})
					wait (2)
					deb = false
					--Gui.Parent.Difficulty.Visible = true
					--Gui.Parent.Text.Visible = true
					--Gui.Parent.Label.Visible = true
					--Gui.Parent.AlreadyFound.Visible = false
					--Gui.Parent.Enabled = false
				else
					if hit.Difficulty.Value == "Easy" then
						Gui.Parent.Difficulty.Text = hit.Difficulty.Value
						Gui.LayoutOrder = -6
						Gui.Parent.Difficulty.TextColor3 = Color3.fromRGB(31, 128, 29)
					elseif hit.Difficulty.Value == "Medium" then
						Gui.Parent.Difficulty.Text = hit.Difficulty.Value
						Gui.LayoutOrder = -5
						Gui.Parent.Difficulty.TextColor3 = Color3.fromRGB(248, 207, 109)
					elseif hit.Difficulty.Value == "Hard" then
						Gui.Parent.Difficulty.Text = hit.Difficulty.Value
						Gui.LayoutOrder = -4
						Gui.Parent.Difficulty.TextColor3 = Color3.fromRGB(196, 40, 28)
					elseif hit.Difficulty.Value == "Very Hard" then
						Gui.Parent.Difficulty.Text = hit.Difficulty.Value
						Gui.LayoutOrder = -3
						Gui.Parent.Difficulty.TextColor3 = Color3.fromRGB(151, 0, 0)
					elseif hit.Difficulty.Value == "Terrifying" then
						Gui.Parent.Difficulty.Text = hit.Difficulty.Value
						Gui.LayoutOrder = -2
						Gui.Parent.Difficulty.TextColor3 = Color3.fromRGB(128, 187, 219)
					elseif hit.Difficulty.Value == "😈" then
						Gui.Parent.Difficulty.Text = hit.Difficulty.Value
						Gui.LayoutOrder = -1
						Gui.Parent.Difficulty.TextColor3 = Color3.fromRGB(27, 42, 53)
					end
					
					if badge ~= nil and badge ~= 0 then
						game.ReplicatedStorage.Badge:FireServer(badge, hit.Name)
						--Gui.Parent.Enabled = true
						--Gui.Text = hit.Name
						--Gui.Parent.ImageLabel.Image = hit.Decal.Texture
						--Gui.Parent.ImageLabel.Visible = true
						script.Collect:Play()

						game.StarterGui:SetCore("SendNotification", {
							Title = "You Found...",
							Text = hit.Name,
							Icon = hit.Decal.Texture
						})
						wait(3)
						deb = false
						--Gui.Parent.ImageLabel.Visible = false
						--Gui.Parent.Enabled = false
					end
				end
			end
		end)
	end
end

How many items do you have in workspace.Flags?

sorry for the late response i just woke up,
but there is 101 flags and they all have these inside of them
image
i dont know if it makes a difference

I just realized, is the error because there is 101 items and it can only load 100 in one minute?

Yes, that’s the problem, only 100 in 1 minute.

so what can i do? to fix this issue?

Do you have all the IDs different or repeated?

Hi sorry for literally 24 hour long respond but i dont understand what you mean, but they are all different ids, if thats what you mean

Do you have 100 different gamepass IDs?

yes there iss 100 different passes

This is a problem, you need to make them smaller…

but there isnt really anything i can do as the game is a pass type game and the entire thing depends on gamepasses. so i guess i cannot add any more items?

This is local script or server script?
Edit: See, local, I don’t see another option, how to make them less than 100 (99 is possible) and before starting the script, make a table where to write whether the player has a gamepass or not, and then check the table already, and not call the function

ok, thank you very much, i am going to try this now

It’s a server-side script since ServerStorage can only be accessed on the server-side

also since BadgeService:UserHasBadgeAsync only works in server script i think

Could you explain what this script is about, what is his usage, and why do you need to check if the user has all theses badges without any action from the user itself?