Pcall slowing my while loop

My goal is to find every gear in the catalog by looping through every id and deciding if its a gear or not and this is my code

local MarketPlaceService = game:GetService("MarketplaceService")
local Id = 0
local TargetId = MarketPlaceService:GetProductInfo(34234)


spawn(function()
	while true do
		Id += 1
		
		pcall(function()
			TargetId = MarketPlaceService:GetProductInfo(Id)
		end)
		
		if TargetId.AssetTypeId == 19 then
			print("Is a gear: " .. Id .. "  ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------")
		else
			print("False")
		end
		
	end	
end)

my problem is that it is running incredibly slow because of the pcall

1 Like

Im pretty sure GetProductInfo Yields when used, which means that it pauses the thread until it gets a result.

You are also arent even using the pcall besides just getting Data, you can just use a second variable to get the Data.

Also, spawn is Deprecated.

3 Likes

the point of the pcall was to make it so when it goes through id’s that are banned/dont exist it dont give an error

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.