Here’s something I wrote earlier that performs the reverse of what you’re trying to achieve (asset ID to catalog ID).
You should be able to repurpose the script for your particular use case.
I decided to modify the linked resource for you.
local marketplace = game:GetService"MarketplaceService"
local getProductInfo = marketplace.GetProductInfo
local assetTypeIds = {2, 11, 12, 13, 21} --T-Shirt, Shirt, Pants, Decal, Badge.
local maxTries = 5 --Maximum retries per catalog ID.
local maxHeight = 100 --Maximum height to search for.
local function getCatalogIdFromAssetId(assetId : number) : number
local success, result = pcall(getProductInfo, marketplace, assetId)
if success then
if result then
if result.AssetTypeId == 1 then
local cache, success2, result2 = table.create(100), nil, nil
repeat
task.wait()
assetId += 1
if assetId - result.AssetId > maxHeight then
return
end
if cache[assetId] then
cache[assetId] += 1
else
cache[assetId] = 1
end
if cache[assetId] > maxTries then
continue
end
success2, result2 = pcall(getProductInfo, marketplace, assetId)
if not success2 then
warn(result2)
assetId -= 1
end
until result2 and table.find(assetTypeIds, result2.AssetTypeId) 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 = getCatalogIdFromAssetId(14417331)
print(assetId) --14417332
The following image was used for testing purposes.
https://www.roblox.com/badges/14417332/John-Loved-of-Muses