UserHasBadgeAsync: Too many requests

So im having an event for my game where with each badge you get an item but when i play it says too many requests. Is there another solution to do? or how do i fix this to make this work

local items = game.ReplicatedStorage:WaitForChild("CharacterItems")
local re = game.ReplicatedStorage:WaitForChild("CharacterCreatorRE")

--local GamepassID = 272441842
local GamepassID = 272441842
local killers5 = 9990336858055
local killers10 = 3403007342183703
local killers20 = 1404797864713005
local surive5 = 85725791531444
local survive10 = 2962182518672635
local survive20 = 2948268688351539 
local survive202 = 2948268688351539
local ducke = 2611232572430591 
local G1x1x1x1 = 2524471727938438 
local defplace = 725700653512226 
local c00lkidd = 1531923169075934 
local remixzy = 4052167012623590
local remixzy666 = 4052167012623590
local hello = 1579906061636035 
local player = game.Players.LocalPlayer

local frame = script.Parent:WaitForChild("AVATAR")
local button = script.Parent.Topbar.EvenLower.TabButtons.Character
frame.Visible = false
button.Visible = true
local eee = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, GamepassID)
local currentItems = {}


--Open and close GUI
button.MouseButton1Click:Connect(function()
	script.Parent.HomePageFrame.Visible = false
	script.Parent.AVATAR.Visible = true
	script.Parent.GamesPageFrame.Visible = false
	script.Parent.ProfileFrame.Visible = false
	script.Parent.MessagesFrame.Visible = false

	
	currentItems = {}
	for i, currentItem in pairs(game.Players.LocalPlayer:WaitForChild("CurrentItems"):GetChildren()) do
		table.insert(currentItems, currentItem.Name)
	end
	
	for x, child in pairs(frame.CharacterViewportFrame:GetChildren()) do
		if child:IsA("Camera") or child:IsA("Model") then child:Destroy() end
	end
	
	local character = game.Players.LocalPlayer.Character
	character.Archivable = true
	local characterModel = character:Clone()
	characterModel.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	characterModel.Name = "Character"
	
	local camera = Instance.new("Camera")
	camera.Parent = frame.CharacterViewportFrame
	frame.CharacterViewportFrame.CurrentCamera = camera
	
	camera.CFrame = CFrame.new(characterModel.PrimaryPart.Position + characterModel.PrimaryPart.CFrame.LookVector * 5, characterModel.PrimaryPart.Position)
	
	characterModel.Parent = frame.CharacterViewportFrame
	
	
	frame.Visible = true
	
	local blur = Instance.new("BlurEffect")
	blur.Name = "CharacterCreatorBlur"
	blur.Parent = game.Lighting
end)

frame.ConfirmTextButton.MouseButton1Click:Connect(function()
	script.Parent.HomePageFrame.Visible = true
	script.Parent.AVATAR.Visible = false
	script.Parent.GamesPageFrame.Visible = false
	script.Parent.ProfileFrame.Visible = false
	script.Parent.MessagesFrame.Visible = false
	--script.Parent.AVATARhat.Visible = false

	
	re:FireServer(currentItems)
	
	frame.Visible = false
	button.Visible = true
	
	if game.Lighting:FindFirstChild("CharacterCreatorBlur") then
		game.Lighting.CharacterCreatorBlur:Destroy()
	end
end)


--Setup character creator GUI
local function setupGui()
	
	for i, child in pairs(frame.CategoriesScrollingFrame:GetChildren()) do
		if child:IsA("TextButton") then child:Destroy() end
	end
	
	for x, category in pairs(items:GetChildren()) do
		
		local categoryName = category.Name
		
		local newCategoryButton = script.ItemCategoryButton:Clone()
		newCategoryButton.Text = categoryName
		
		newCategoryButton.MouseButton1Click:Connect(function()
			
			for y, child in pairs(frame.ItemsScrollingFrame:GetChildren()) do
				if child:IsA("TextButton") then child:Destroy() end
			end
			
			local debounce = false
			
			for z, item in pairs(category:GetChildren()) do
				local itemType = item:FindFirstChildOfClass("Shirt") or item:FindFirstChildOfClass("Pants") or item
				local itemName = itemType.Name
				
				local newItemButton = script.ItemButton:Clone()
				
				newItemButton.Name = itemName
				newItemButton.ItemName.Text = itemName
				newItemButton.Info.Text = "Equip"
				---SECRET ITEMS-----------------
				if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, GamepassID) then
					if newItemButton.Name == "BC Hard Hat" then 
						newItemButton.Visible = true
					end
				else
					if newItemButton.Name == "BC Hard Hat" then
						newItemButton.Visible = false
					end
				end
				if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, killers5) then
					if newItemButton.Name == "Shutter Shades_Adurite" then 
						newItemButton.Visible = true
					end
				else
					if newItemButton.Name == "Shutter Shades_Adurite" then
						newItemButton.Visible = false
					end
				end
				wait(.1)
			---	if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, killers10) then
				--	if newItemButton.Name == "AduriteTeapot" then 
				--		newItemButton.Visible = true
				--	end
			--	else
				--	if newItemButton.Name == "AduriteTeapot" then
				--		newItemButton.Visible = false
				--	end
				--end
				--wait(.1)
				if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, killers20) then
					if newItemButton.Name == "AduriteAntlers" then 
						newItemButton.Visible = true
					end
				else
					if newItemButton.Name == "AduriteAntlers" then
						newItemButton.Visible = false
					end
				end
				wait(.1)
			--	if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, surive5) then
				--	if newItemButton.Name == "AduriteBeautifulHair" then 
				--		newItemButton.Visible = true
				--	end
			--	else
				--	if newItemButton.Name == "AduriteBeautifulHair" then
				--		newItemButton.Visible = false
				--	end
				--end
				wait(.1)
				if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, survive10) then
					if newItemButton.Name == "AduriteSwordpack" then 
						newItemButton.Visible = true
					end
				else
					if newItemButton.Name == "AduriteSwordpack" then
						newItemButton.Visible = false
					end
				end
				wait(.1)
				if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, survive20) then
					if newItemButton.Name == "AduriteFedora" then 
						newItemButton.Visible = true
					end
				else
					if newItemButton.Name == "AduriteFedora" then
						newItemButton.Visible = false
					end
				end
				wait(.1)
				if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, ducke) then
					if newItemButton.Name == "RubberDuckie" then 
						newItemButton.Visible = true
					end
				else
					if newItemButton.Name == "RubberDuckie" then
						newItemButton.Visible = false
					end
				end
				wait(.1)
				if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, G1x1x1x1) then
					if newItemButton.Name == "1x1x1x1 Sword" then 
						newItemButton.Visible = true
					end
				else
					if newItemButton.Name == "1x1x1x1 Sword" then
						newItemButton.Visible = false
					end
				end
				wait(.1)
				if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, c00lkidd) then
					if newItemButton.Name == "c00lkidd SwordPack" then 
						newItemButton.Visible = true
					end
				else
					if newItemButton.Name == "c00lkidd SwordPack" then
						newItemButton.Visible = false
					end
				end
				wait(.1)
				if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, defplace) then
					if newItemButton.Name == "Classic Vending Machine Backpack" then 
						newItemButton.Visible = true
					end
				else
					if newItemButton.Name == "Classic Vending Machine Backpack" then
						newItemButton.Visible = false
					end
				end
				wait(.1)
				if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, survive202) then
					if newItemButton.Name == "AduriteTophat" then 
						newItemButton.Visible = true
					end
				else
					if newItemButton.Name == "AduriteTophat" then
						newItemButton.Visible = false
					end
				end
				wait(.1)
				if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, remixzy) then
					if newItemButton.Name == "AduriteClockworksShades" then 
						newItemButton.Visible = true
					end
				else
					if newItemButton.Name == "AduriteClockworksShades" then
						newItemButton.Visible = false
					end
				end
				wait(.1)
				if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, remixzy666) then
					if newItemButton.Name == "AduriteHeadphones" then 
						newItemButton.Visible = true
					end
				else
					if newItemButton.Name == "AduriteHeadphones" then
						newItemButton.Visible = false
					end
				end
				wait(.1)
				if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, hello) then
					if newItemButton.Name == "AduriteVisor" then 
						newItemButton.Visible = true
					end
				else
					if newItemButton.Name == "AduriteVisor" then
						newItemButton.Visible = false
					end
				end
				wait(.1)
	
	
	--END OF SECRET ITEMS----
	
	
	





				if item:GetAttribute("BCITEM") == true then 
					newItemButton.BC.Visible = true
				else
					newItemButton.BC.Visible = false
				end
				
				if item:GetAttribute("Limited") == true then 
					newItemButton.LimitedTag.Visible = true
				else
					newItemButton.LimitedTag.Visible = false
				end
				if table.find(currentItems, itemType.Name) then newItemButton.Info.Text = "Remove" end
				
				local camera = Instance.new("Camera")
				camera.Parent = newItemButton.ItemViewportFrame
				newItemButton.ItemViewportFrame.CurrentCamera = camera
				
				local itemModel = item:Clone()
				local itemMainPart = itemModel:FindFirstChild("Handle") or itemModel.PrimaryPart
				
				if itemModel:FindFirstChild("Humanoid") then
					itemModel.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
				end
				
				local distance = 6				
				if itemMainPart.Name == "Handle" then distance = 2 end
				camera.CFrame = CFrame.new(itemMainPart.Position + itemMainPart.CFrame.LookVector * distance, itemMainPart.Position)
				
				newItemButton.MouseButton1Click:Connect(function()
					
					if frame.CharacterViewportFrame:FindFirstChild("Character") and not debounce then
						debounce = true
						if not table.find(currentItems, itemType.Name) then
							table.insert(currentItems, itemType.Name)
							
							newItemButton.Info.Text = "Remove"
							
							local itemToApply = itemType:Clone()
							
							if itemType:IsA("Shirt") then
								
								if frame.CharacterViewportFrame.Character:FindFirstChildOfClass("Shirt") then
									for i, item in pairs(currentItems) do
										if items:FindFirstChild(item, true) and items:FindFirstChild(item, true):IsA("Shirt") then
											table.remove(currentItems, i)
										end
									end
									if frame.ItemsScrollingFrame:FindFirstChild(frame.CharacterViewportFrame.Character:FindFirstChildOfClass("Shirt").Name) then
										frame.ItemsScrollingFrame:FindFirstChild(frame.CharacterViewportFrame.Character:FindFirstChildOfClass("Shirt").Name).Info.Text = "Equip"
									end
									for i, child in pairs(frame.CharacterViewportFrame.Character:GetChildren()) do
										if child:IsA("Shirt") then child:Destroy() end
									end
								end
								itemToApply.Parent = frame.CharacterViewportFrame.Character
								elseif itemType:IsA("ShirtGraphic") then

									if frame.CharacterViewportFrame.Character:FindFirstChildOfClass("ShirtGraphic") then
										for i, item in pairs(currentItems) do
											if items:FindFirstChild(item, true) and items:FindFirstChild(item, true):IsA("ShirtGraphic") then
												table.remove(currentItems, i)
											end
										end
										if frame.ItemsScrollingFrame:FindFirstChild(frame.CharacterViewportFrame.Character:FindFirstChildOfClass("ShirtGraphic").Name) then
											frame.ItemsScrollingFrame:FindFirstChild(frame.CharacterViewportFrame.Character:FindFirstChildOfClass("ShirtGraphic").Name).Info.Text = "Equip"
										end
										for i, child in pairs(frame.CharacterViewportFrame.Character:GetChildren()) do
											if child:IsA("ShirtGraphic") then child:Destroy() end
										end
									end
									itemToApply.Parent = frame.CharacterViewportFrame.Character
								
							elseif itemType:IsA("Pants") then
								
								if frame.CharacterViewportFrame.Character:FindFirstChildOfClass("Pants") then
									for i, item in pairs(currentItems) do
										if items:FindFirstChild(item, true) and items:FindFirstChild(item, true):IsA("Pants") then
											table.remove(currentItems, i)
										end
									end
									if frame.ItemsScrollingFrame:FindFirstChild(frame.CharacterViewportFrame.Character:FindFirstChildOfClass("Pants").Name) then
										frame.ItemsScrollingFrame:FindFirstChild(frame.CharacterViewportFrame.Character:FindFirstChildOfClass("Pants").Name).Info.Text = "Equip"
									end
									for i, child in pairs(frame.CharacterViewportFrame.Character:GetChildren()) do
										if child:IsA("Pants") then child:Destroy() end
									end
								end
								itemToApply.Parent = frame.CharacterViewportFrame.Character
							
								
							
							elseif itemType:IsA("Accessory") then
								
								local c = frame.CharacterViewportFrame.Character
								c.Parent = workspace
								
								itemToApply.Parent = c
								local a1 = itemToApply.Handle:FindFirstChildOfClass("Attachment")
								local a0 = c.Head[a1.Name]
								
								local weld = Instance.new("Weld")
								weld.Part0 = a0.Parent
								weld.Part1 = a1.Parent
								weld.C0 = a0.CFrame
								weld.C1 = a1.CFrame
								weld.Parent = a0.Parent
								
								local po = itemToApply.Handle.Position - c.Head.Position
								local ro = itemToApply.Handle.Orientation - c.Head.Orientation
								
								c.Parent = frame.CharacterViewportFrame
								itemToApply.Parent = c
								
								local atch = itemToApply.Handle:FindFirstChildOfClass("Attachment")
								itemToApply.Handle.CFrame = c.Head.CFrame * CFrame.new(po) * CFrame.Angles(math.rad(ro.Z), math.rad(ro.Y), math.rad(ro.X))
							end
							
						else
							table.remove(currentItems, table.find(currentItems, itemType.Name))
							
							newItemButton.Info.Text = "Remove"
							frame.CharacterViewportFrame.Character[itemName]:Destroy()
						end
					end
					wait(1)
					debounce = false
				end)
				
				itemModel.Parent = newItemButton.ItemViewportFrame
				
				newItemButton.Parent = frame.ItemsScrollingFrame
				newItemButton.Size = UDim2.new(0, newItemButton.AbsoluteSize.X, 0, newItemButton.AbsoluteSize.Y)
				frame.ItemsScrollingFrame.CanvasSize = UDim2.new(0, 0, 0, frame.ItemsScrollingFrame.UIGridLayout.AbsoluteContentSize.Y)
			end
		end)
		
		newCategoryButton.Parent = frame.CategoriesScrollingFrame
		newCategoryButton.Size = UDim2.new(0, newCategoryButton.AbsoluteSize.X, 0, newCategoryButton.AbsoluteSize.Y)
		frame.CategoriesScrollingFrame.CanvasSize = UDim2.new(0, frame.CategoriesScrollingFrame.UIGridLayout.AbsoluteContentSize.X, 0, 0)
	end
end

setupGui()
items.DescendantAdded:Connect(setupGui)
1 Like

BadgeService | Documentation - Roblox Creator Hub.
According to the documentation, there is a rate limit. You could probably limit the amount of requests per minute to something like 35 for each player. (Like have it check for 35 of the badges and then wait a minute)