Best method of getting the template ID of clothing?

I have tried the subtracting one from the ID and comparing the creator IDs of both items until they match, but this method does not work for group items as the template and asset have different creator IDs.

15 Likes

I’m pretty sure that Roblox Studio converts the ID automatically - so just take the shirt link and put it into the “ShirtTemplate” section of a shirt. From there you could parse it or do whatever you need to do.

I’m not sure if there’s a more direct way though.

10 Likes

If you are doing this manually it can very easily be done by putting a decal onto a brick in studio and then copying the clothing asset into the texture field on the decal, which then gives you back the image asset id. It might be possible to do this with a script, but i haven’t tried it

10 Likes

This won’t work since I am not doing this manually in studio, but instead, players are allowed to put clothing IDs on mannequins in game and then sell them there.

3 Likes

Ah darn. I’m gonna keep looking into this because this is annoying the heck out of me. Studio does convert it somehow from a shirt to an image, but you have to press enter for it to convert. :huh:

EDIT: This leads me to believe there isn’t an easy/direct/normal way to do this.

5 Likes

I’ve been trying to find a fix all day for this issue, but it’s quite frustrating as Roblox does not seem to offer any way to get the template id.

1 Like

Honestly I’m not sure if there is another method other than the super tedious way of going through them one by one

2 Likes

Was a solution ever found for this?

I am attempting to do this exact same thing. This points to Convert Decal asset id to Image asset id - #2 by GeorgeOfAIITrades thumbnails, but clearly that is not what we’re doing. We’re attempting to use clothing.

1 Like

Here’s a link to an article explaining how to do it:

But for people who just want to read I’ll give a quick break down:

  1. Get the asset id from the catalog URL
  2. Use game:GetService("InsertService"):LoadAsset(assetIdHere) to load a model of the shirt into the game
  3. Parent the shirt from the newly created model into the player’s character, or simply extract the id from the shirt in the model and edit the one on the player’s character to match it
19 Likes
local marketplace = game:GetService"MarketplaceService"
local getProductInfo = marketplace.GetProductInfo

local assetTypeIds = {2, 11, 12, 13} --T-Shirt, Shirt, Pants, Decal.
local maxTries = 5 --Maximum retries per catalog ID.
local maxDepth = 100 --Maximum depth to search for.

local function getAssetIdFromCatalogId(catalogId : number) : number
	local success, result = pcall(getProductInfo, marketplace, catalogId)
	if success then
		if result then
			if table.find(assetTypeIds, result.AssetTypeId) or (result.AssetTypeId == 21 and catalogId <= 2124343749) then --Badges with an ID below 2124343749 (before they were given their own URL directory).
				local cache, success2, result2 = table.create(100), nil, nil
				repeat
					task.wait()
					catalogId -= 1
					if result.AssetId - catalogId > maxDepth then
						return
					end
					if cache[catalogId] then
						cache[catalogId] += 1
					else
						cache[catalogId] = 1
					end
					if cache[catalogId] > maxTries then
						continue
					end
					success2, result2 = pcall(getProductInfo, marketplace, catalogId)
					if not success2 then
						warn(result2)
						catalogId += 1
					end
				until result2 and result2.Creator.CreatorType == result.Creator.CreatorType and result2.Creator.CreatorTargetId == result.Creator.CreatorTargetId
				return result2.AssetId
			end
		end
	else
		warn(result)
	end
end

local assetId = getAssetIdFromCatalogId(14417332)
print(assetId) --14417331

Here’s an implentation which works for all asset types where this behavior is observed (decals, t-shirts, shirts, pants & badges).

The following badge was used for testing purposes.
https://www.roblox.com/badges/14417332/John-Loved-of-Muses

6 Likes

For anyone still needing this, here’s an experience I made a while back.

This is the code for it:

function getId(assetId)
	local success, model = pcall(function() 
		return InsertService:LoadAsset(assetId) 
	end)
	if success then 
		model.Parent = workspace
		local clothing = model:FindFirstChildWhichIsA("Clothing")
		if clothing:IsA("Pants") then
			return clothing.PantsTemplate
		elseif clothing:IsA("Shirt") then
			return clothing.ShirtTemplate
		else
			error("Unexpected type of asset")
		end
	else
		error("Request for " .. tostring(assetId) .. " failed: " .. tostring(model))
	end
end
7 Likes
local game = game
local insertService = game:GetService("InsertService")
local loadAsset = insertService.LoadAsset

local classToPropertyMap = {["Shirt"] = "ShirtTemplate", ["Pants"] = "PantsTemplate", ["ShirtGraphic"] = "Graphic"}

local function getAssetIdFromCatalogId(catalogId)
    local success, result = pcall(loadAsset, insertService, catalogId)
    if success then
        for className, propertyName in pairs(classToPropertyMap) do
            local clothing = result:FindFindFirstChildOfClass(className)
            if clothing then return clothing[propertyName] end
        end
    else
        warn(result)
    end
end

local tShirtAssetId = getAssetIdFromCatalogId(1028595) --bloxxer
print(tShirtAssetId) --1028594
local shirtAssetId = getAssetIdFromCatalogId(607785314) --roblox jacket
print(shirtAssetId) --607785311
local pantsAssetId = getAssetIdFromCatalogId(129459077) --black slacks
print(pantsAssetId) --129459076

Added t-shirts.

Thank you! I updated the experience to support this. By the way, your code is slightly wrong, the ShirtGraphic is called ‘Shirt Graphic’, not ‘Clothing’. I fixed this by using

local clothing = (model:GetChildren())[1]

*It works properly in the experience.

My edit didn’t go through before.

1 Like