How to change the Avatar Item's assestId to Texture Id in script?

My Code:

local Players = game:GetService("Players")
local HttpService = game:GetService("HttpService")
local MarketplaceService = game:GetService("MarketplaceService")
local Workspace = game:GetService("Workspace")

local config = {
	products = false,
	shirts = true,
	pants = true,
	ugc = true,
}

local function handleRequestErrors(success: boolean, result: string): any
	if not success then
		return nil
	end
	
	local decodeSuccess, decodedResult = pcall(HttpService.JSONDecode, HttpService, result)
	if not decodeSuccess then
		return nil
	end
	
	return decodedResult
end

local function getUserGamepasses(userId: number)
	if not config.gamepasses then return end
	
	local gamesUrl = "https://games.roproxy.com/v2/users/" .. userId .. "/games?accessFilter=2&limit=50&sortOrder=Asc"
	local success, result = pcall(function()
		return HttpService:GetAsync(gamesUrl)
	end)
	
	local decodedGamesResult = handleRequestErrors(success, result)
	
	if decodedGamesResult and decodedGamesResult.data and #decodedGamesResult.data > 0 then
		for _, gameInfo in ipairs(decodedGamesResult.data) do
			local gameId = gameInfo.id
			local gamepassesUrl = "https://games.roproxy.com/v1/games/" .. gameId .. "/game-passes?limit=100&sortOrder=Asc"
			
			local success2, result2 = pcall(function()
				return HttpService:GetAsync(gamepassesUrl)
			end)
			
			local decodedGamepassesResult = handleRequestErrors(success2, result2)
			
			if decodedGamepassesResult and decodedGamepassesResult.data and #decodedGamepassesResult.data > 0 then
				for _, gamepassDetail in ipairs(decodedGamepassesResult.data) do
					if gamepassDetail.price then
						print(`Game Pass Adı: {gamepassDetail.displayName}, Fiyat: {gamepassDetail.price} Robux, Oyun ID: {gameId}`)
					end
				end
			end
		end
	end
end

local function getUserCreatedCatalogItems(username: string, assetType: string)
	local categoryId = 0
	if assetType == "Shirt" then
		if not config.shirts then return end
		categoryId = 12
	elseif assetType == "Pants" then
		if not config.pants then return end
		categoryId = 13
	elseif assetType == "UGC" then
		if not config.ugc then return end
		categoryId = 3
	end
	
	if categoryId == 0 then return end
	
	local url = `https://catalog.roproxy.com/v1/search/items/details?Category={categoryId}&CreatorName={username}`
	local success, result = pcall(function()
		return HttpService:GetAsync(url)
	end)
	
	local decodedResult = handleRequestErrors(success, result)
	
	if decodedResult and decodedResult.data and #decodedResult.data > 0 then
		for _, item in ipairs(decodedResult.data) do
			if item.price then
				print(`{assetType} Adı: {item.name}, Fiyat: {item.price} Robux, AssetId: {item.id}`)
			end
		end
	end
end

local function getUserDeveloperProducts(userId: number)
	if not config.products then return end
	
	local gamesUrl = `https://games.roproxy.com/v2/users/{userId}/games?accessFilter=2&limit=50&sortOrder=Asc`
	local success, result = pcall(function()
		return HttpService:GetAsync(gamesUrl)
	end)
	
	local decodedGamesResult = handleRequestErrors(success, result)
	
	if decodedGamesResult and decodedGamesResult.data and #decodedGamesResult.data > 0 then
		for _, gameInfo in ipairs(decodedGamesResult.data) do
			local productIdUrl = `https://develop.roproxy.com/v1/assets/{gameInfo.id}/product-ids`
			
			local success2, result2 = pcall(function()
				return HttpService:GetAsync(productIdUrl)
			end)
			
			local decodedProductResult = handleRequestErrors(success2, result2)
			
			if decodedProductResult and decodedProductResult.data and #decodedProductResult.data > 0 then
				for _, productId in ipairs(decodedProductResult.data) do
					print(`Product ID: {productId}, Oyun Adı: {gameInfo.name}, Oyun ID: {gameInfo.id}`)
				end
			end
		end
	end
end

local placesFolder = Workspace:WaitForChild("places")

local function setupStand(stand)
	local ownerIdValue = stand:WaitForChild("OwnerId", 10)
	local proxyPart = stand:WaitForChild("Proxy", 10)
	
	if not ownerIdValue or not proxyPart or not proxyPart:WaitForChild("ProximityPrompt", 10) then
		warn(`Stand "${stand.Name}" için gerekli parçalar bulunamadı.`)
		return
	end
	
	local prompt = proxyPart:WaitForChild("ProximityPrompt")
	
	ownerIdValue.Changed:Connect(function(newOwnerId)
		if newOwnerId ~= 0 then
			local player = Players:GetPlayerByUserId(newOwnerId)
			if player then
				print("--- Yeni stand sahibi:", player.Name, "---")
				getUserCreatedCatalogItems(player.Name, "Shirt")
				getUserCreatedCatalogItems(player.Name, "Pants")
				getUserCreatedCatalogItems(player.Name, "UGC")
				getUserGamepasses(player.UserId)
				getUserDeveloperProducts(player.UserId)
				print("-------------------------------------------------")
			end
		end
	end)
end

for _, stand in ipairs(placesFolder:GetChildren()) do
	setupStand(stand)
end

placesFolder.ChildAdded:Connect(setupStand)

There’s a problem. With this code, I get the AssestID of the shirts and pants sold by the player. However, when I change the template of a shirt or pants with the code, the image doesn’t appear. However, when I manually enter the AssestID in Studio, the AssestID is automatically changed and the image of thisrt/pants appears.

1 Like

This content ID is different than the website URL of the shirt. It can be found by pasting the website URL of the shirt into the ShirtTemplate property in Studio.

So, from what I understand the asset ID is not the texture ID, and it needs the texture ID. It works when you manually put it because Studio does it for you, but it doesn’t do it automatically in scripts.

https://create.roblox.com/docs/reference/engine/classes/Shirt

It says InsertService can be used to get the shirt from the asset ID. Maybe you can do that?

1 Like

thanks for response. I’m trying to do it.

Problem Solved! If anyone is wondering, I used the InsertService service.
Sample Code:

local InsertService = game:GetService("InsertService")
local Workspace = game:GetService("Workspace")

-- This Functoin create a Model from AssetId
local success, model = pcall(function()
	return InsertService:LoadAsset(132068251612007)
end)

if success then
	model.Parent = workspace
	local textureId = model:FindFirstChild("Shirt")
	script.Parent.ShirtTemplate = textureId.ShirtTemplate
end

image

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