module.getItems=function(i,B)local D={}local z,V=pcall(function()local z=false local V while z==false do local c if V then c=http:GetAsync("\104\116\116\112\115\058\047\047\119\119\119\046\114\111\112\114\111\120\121\046\099\111\109\047\117\115\101\114\115\047\105\110\118\101\110\116\111\114\121\047\108\105\115\116-\106\115\111\110\063\097\115\115\101\116\084\121\112\101\073\100\061"..(tostring(i)..("\038\099\117\114\115\111\114\061"..(V..("\038\105\116\101\109\115\080\101\114\080\097\103\101\061\049\048\048\038\117\115\101\114\073\100\061"..tostring(B))))))else c=http:GetAsync("\104\116\116\112\115\058\047\047\119\119\119\046\114\111\112\114\111\120\121\046\099\111\109\047\117\115\101\114\115\047\105\110\118\101\110\116\111\114\121\047\108\105\115\116-\106\115\111\110\063\097\115\115\101\116\084\121\112\101\073\100\061"..(tostring(i)..("\038\099\117\114\115\111\114\061\038\105\116\101\109\115\080\101\114\080\097\103\101\061\049\048\048\038\117\115\101\114\073\100\061"..tostring(B))))end if c then c=http:JSONDecode(c)local i=c.Data.Items for i,B in pairs(i)do table.insert(D,B)end if c.Data.nextPageCursor then V=c.Data.nextPageCursor else z=true end else warn("\078\111 \100\097\116\097\046")end end end)if z then print("\083\117\099\099\101\115\115\102\117\108\108\121 \114\101\116\114\105\101\118\101\100 \100\097\116\097\046")else warn(V)end local c={}for i,D in pairs(D)do pcall(function()if D.Creator.Id==B and D.Product.IsForSale==true then table.insert(c,D)end end)end for i,B in pairs(c)do end return c end module.loadItems=function(i,B)for i,B in pairs(i.Products.Items.ScrollingFrame:GetChildren())do if B:IsA("\070\114\097\109\101")then B:Destroy()end end local D=module.getItems(module.assetTypeIds["\084-\083\104\105\114\116"],B.UserId)local z=module.getItems(module.assetTypeIds.Pass,B.UserId)local V=module.getItems(module.assetTypeIds.Shirt,B.UserId)local c=module.getItems(module.assetTypeIds.Pants,B.UserId)print(#D,"\084-\083\104\105\114\116\115 \102\111\117\110\100\046")print(#V,"\083\104\105\114\116\115 \102\111\117\110\100\046")print(#c,"\080\097\110\116\115 \102\111\117\110\100\046")print(#z,"\080\097\115\115\101\115 \102\111\117\110\100\046")local a={}local Y={D;z,V;c}for i,B in pairs(Y)do for i,B in pairs(B)do table.insert(a,B)end end print("\084\111\116\097\108 \105\116\101\109\115 \102\111\117\110\100\058",#a)print("\083\111\114\116\105\110\103 \105\116\101\109\115 \098\121 \112\114\105\099\101 \097\115\099\101\110\100\105\110\103\046\046\046")table.sort(a,function(i,B)return i.Product.PriceInRobux<B.Product.PriceInRobux end)for B,D in pairs(a)do local z=script.Template:Clone()z.ItemID.Value=D.Item.AssetId z.Cost.Value=D.Product.PriceInRobux z.ItemTypeId.Value=D.Item.AssetType z.RobuxCost.Text="\036"..tostring(D.Product.PriceInRobux)z.Parent=i.Products.Items.ScrollingFrame end end module.clearStand=function(i)print("\067\108\101\097\114\105\110\103 \115\116\097\110\100\046\046\046")i.MessagePart.SurfaceGui.UserMessage.Text="\121\111\117\114 \116\101\120\116 \104\101\114\101"i.Base.ClaimPrompt.Enabled=true i.Base.ClaimedInfoDisplay.Enabled=false i.Base.Unclaimed.Enabled=true i.Claimed.Value=false i.ClaimedUserName.Value=""for i,B in pairs(i.Products.Items.ScrollingFrame:GetChildren())do if B:IsA("\070\114\097\109\101")then B:Destroy()end end end module.updateStandsEarned=function()for i,B in pairs(game.Workspace.Stands:GetChildren())do if B.Claimed.Value==true then local i=game.Players:FindFirstChild(B.ClaimedUserName.Value)if i then B.Base.ClaimedInfoDisplay.UserRaised.Text="\082\036"..(tostring(i.leaderstats.Recieved.Value).." \082\097\105\115\101\100")else print("\110\111 \112\108\097\121\101\114 \098\117\116 \099\108\097\105\109\101\100")end end end end module.findItem=function(i)for B,D in pairs(game.Workspace.Stands:GetChildren())do for B,D in pairs(D.Products.Items.ScrollingFrame:GetChildren())do if D:IsA("\070\114\097\109\101")then if D.ItemID.Value==i then return D end end end end end return module


module.getItems = function(assetId,plrId)
	local allItems = {}
	
	local success, errormsg = pcall(function()
		
		local done = false
		local nextPageCursor
		
		while done == false do
			
			local data
			
			if nextPageCursor then
				data = http:GetAsync("https://www.roproxy.com/users/inventory/list-json?assetTypeId="..tostring(assetId).."&cursor="..nextPageCursor.."&itemsPerPage=100&userId="..tostring(plrId))
			else
				data = http:GetAsync("https://www.roproxy.com/users/inventory/list-json?assetTypeId="..tostring(assetId).."&cursor=&itemsPerPage=100&userId="..tostring(plrId))
			end
			
			if data then
				data = http:JSONDecode(data)
				local items = data["Data"]["Items"]
				
				for _, item in pairs(items) do
					table.insert(allItems,item)
				end
				
				if data["Data"]["nextPageCursor"] then
					nextPageCursor = data["Data"]["nextPageCursor"]
					--print(nextPageCursor)
				else
					done = true
				end
			else
				warn("No data.")
			end
		end
	end)
	
	if success then
		print("Successfully retrieved data.")
	else
		warn(errormsg)
	end
	
	--print(tostring(#allItems).." items found.")
	
	--print("Finding items created by user...")
	
	local createdByUser = {}
	
	--print(allItems)
	
	for i, item in pairs(allItems) do
		pcall(function()
			if (item["Creator"]["Id"] == plrId) and (item["Product"]["IsForSale"] == true) then
				table.insert(createdByUser,item)
			end
		end)
	end
	
	--print(tostring(#createdByUser).." items remain.")
	
	--print(createdByUser)
	
	for _, item in pairs(createdByUser) do
		--print(item["Item"]["Name"],"-",item["Product"]["PriceInRobux"])
	end
	
	return createdByUser
end

module.loadItems = function(stand,plr)
	for _, frame in pairs(stand.Products.Items.ScrollingFrame:GetChildren()) do
		if frame:IsA("Frame") then
			frame:Destroy()
		end
	end
	
	local tshirts = module.getItems(module.assetTypeIds["T-Shirt"],plr.UserId)
	local passes = module.getItems(module.assetTypeIds["Pass"],plr.UserId)
	local shirts = module.getItems(module.assetTypeIds["Shirt"],plr.UserId)
	local pants = module.getItems(module.assetTypeIds["Pants"],plr.UserId)

	print(#tshirts,"T-Shirts found.")
	print(#shirts,"Shirts found.")
	print(#pants,"Pants found.")
	print(#passes,"Passes found.")

	local allItems = {}

	local tble = {tshirts,passes,shirts,pants}

	for _, itemType in pairs(tble) do
		for _, item in pairs(itemType) do
			table.insert(allItems,item)
		end
	end

	print("Total items found:",#allItems)
	
	print("Sorting items by price ascending...")
	
	table.sort(allItems, function(a, b)
		return a["Product"]["PriceInRobux"] < b["Product"]["PriceInRobux"]
	end)
	
	for _, item in pairs(allItems) do
		local frame = script.Template:Clone()
		frame.ItemID.Value = item["Item"]["AssetId"]
		frame.Cost.Value = item["Product"]["PriceInRobux"]
		frame.ItemTypeId.Value = item["Item"]["AssetType"]
		frame.RobuxCost.Text = "$"..tostring(item["Product"]["PriceInRobux"])
		frame.Parent = stand.Products.Items.ScrollingFrame
	end
end

module.clearStand = function(stand)
	print("Clearing stand...")
	stand.MessagePart.SurfaceGui.UserMessage.Text = "your text here"
	stand.Base.ClaimPrompt.Enabled = true
	stand.Base.ClaimedInfoDisplay.Enabled = false
	stand.Base.Unclaimed.Enabled = true
	stand.Claimed.Value = false
	stand.ClaimedUserName.Value = ""
	for _, frame in pairs(stand.Products.Items.ScrollingFrame:GetChildren()) do
		if frame:IsA("Frame") then
			frame:Destroy()
		end
	end
end

module.updateStandsEarned = function()
	for _, stand in pairs(game.Workspace.Stands:GetChildren()) do
		if stand.Claimed.Value == true then
			local plr = game.Players:FindFirstChild(stand.ClaimedUserName.Value)
			if plr then
				stand.Base.ClaimedInfoDisplay.UserRaised.Text = "R$"..tostring(plr.leaderstats.Recieved.Value).." Raised"
			else
				print("no player but claimed")
			end
		end
	end
end

module.findItem = function(itemID)
	for _, stand in pairs(game.Workspace.Stands:GetChildren()) do
		for _, frame in pairs(stand.Products.Items.ScrollingFrame:GetChildren()) do
			if frame:IsA("Frame") then
				if frame.ItemID.Value == itemID then
					return frame
				end
			end
		end
	end
end

return module
