How Do I Make A Random UGC Accessory Display On An Image Label Once I Click A Button?

Greetings to all Developers, thanks a lot for taking a quick look at my topic. The question is, how do I make a random UGC Catalog Accessory display on an ImageLabel once I click on an ImageButton. It must be any Accessory(Gears are also accessories…) that is Available, and the creator can be anyone. It doesn’t matter when it was created, and it can have any price as long as it is on sale. Since the only thing I’m using right now is Gui's, everything is obviously located in StarterGui. The issue is that I don’t know how I’m going to make this work, but I’m assuming that I need to use game:GetService(""), since there are some services that might help. Yet again, the problem is that I don’t know, and I’m not sure. I’ve tried downloading and pasting some images from the catalog into my game. The problem with this is that, A: On large screen devices images stretch to fit the screen and distort the images, and B: I have to rely on only the images that I downloaded, meaning that the same images will appear over and over again.

That’s a bit to comprehend, but if reading is not your thing, here’s a video explaining pretty much everything I just said.

1 Like

AvatarEditorService:SearchCatalog()

2 Likes

What am I supposed to put between parenthesis? :point_down: :point_down: :point_down:
AvatarEditorService:SearchCatalog(*What do i put here?*)

It keeps giving me an error for anything I put.

1 Like

Here’s an example:

local params = CatalogSearchParams.new()
params.CategoryFilter = Enum.CatalogCategoryFilter.CommunityCreations
params.SearchKeyword = "Hat"

local pages = AES:SearchCatalog(params)
	
while wait() do
	for i, data in pairs(pages:GetCurrentPage()) do
		print(data.ProductId)
		screenGui.ImageLabel.Image = "rbxthumb://type=Asset&id="..data.ProductId.."&w=420&h=420"
		task.wait(.5)
	end

	if pages.IsFinished then break end
	pages:AdvanceToNextPageAsync()
end
1 Like

This keeps happening for some reason.

This is the script for the ImageButton :point_down: :point_down: :point_down:

local AES = game:GetService("AvatarEditorService")
local AssetImage = script.Parent.Parent.Parent.PriceGuessing.AssetImage

local params = CatalogSearchParams.new()
params.CategoryFilter = Enum.CatalogCategoryFilter.CommunityCreations
params.SearchKeyword = "Hat"

local pages = AES:SearchCatalog(params)

script.Parent.MouseButton1Click:Connect(function()
	while wait() do
		for i, data in pairs(pages:GetCurrentPage()) do
			print(data.ProductId)
			AssetImage.Image = "rbxthumb://type=Asset&id="..data.ProductId.."&w=420&h=420"
			task.wait(.5)
		end

		if pages.IsFinished then break end
		pages:AdvanceToNextPageAsync()
	end
	AssetImage.Visible = true
end)
2 Likes
local AES = game:GetService("AvatarEditorService")
local assetImage = script.Parent

local params = CatalogSearchParams.new()
params.CategoryFilter = Enum.CatalogCategoryFilter.CommunityCreations
params.SortType = Enum.CatalogSortType.RecentlyCreated
params.AssetTypes = {
	Enum.AvatarAssetType.Hat;
	Enum.AvatarAssetType.HairAccessory;
	Enum.AvatarAssetType.FaceAccessory;
	Enum.AvatarAssetType.NeckAccessory;
	Enum.AvatarAssetType.ShoulderAccessory;
	Enum.AvatarAssetType.FrontAccessory;
	Enum.AvatarAssetType.BackAccessory;
	Enum.AvatarAssetType.WaistAccessory;
}
params.IncludeOffSale = false

local pages = AES:SearchCatalog(params)
local tab = {}

local scanning = false
assetImage.MouseButton1Click:Connect(function()
	if scanning then
		print("local tab = {"..table.concat(tab, ", ").."}")
	end
	
	if #tab > 0 then
		assetImage.Image = "rbxthumb://type=Asset&id="..tab[math.random(#tab)].."&w=420&h=420"
	else
		scanning = true
		while wait() do
			for i, data in pairs(pages:GetCurrentPage()) do
				assetImage.Image = "rbxthumb://type=Asset&id="..data.Id.."&w=420&h=420"
				table.insert(tab, data.Id)
				task.wait(1)
			end

			if pages.IsFinished then break end
			pages:AdvanceToNextPageAsync()
		end
	end
end)
4 Likes

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