The above reply will only make the image load, not fetch the decal ID.
A solution to fetching the decal id is brute forcing by taking advantage of the fact that the decal id is the asset id, incremented by a small amount, usually less than 10. Here’s a solution that uses brute force to find the answer:
local MarketplaceService = game:GetService("MarketplaceService")
local assetId = 0
local lookAhead = 10 --check 10 ids ahead
--The type checking is to make your life easier if you want to modify the isTheDecal function
type creator = {CreatorTargetId: number, CreatorType: string, HasVerifiedBadge: boolean, Id: number, Name: string}
type productInfo = {AssetId: number, AssetTypeId: number, ContentRatingTypeId: number, Created: string,
Creator: creator, Description: string, IconImageAssetId: number, IsForSale: boolean, IsLimited: boolean,
IsLimitedUnique: boolean, IsNew: boolean, IsPublicDomain: boolean, MinimumMembershipLevel: number,
Name: string, ProductId: number, ProductType: string, Sales: number, TargetId: number, Updated: string}
local function getInfo(id: number): productInfo?
local success, response = pcall(function()
return MarketplaceService:GetProductInfo(id)
end)
if success then
return response
else
if response:find("not a valid assetId") then return nil end
warn(response)
return getInfo(id)
end
end
--determines if the decal belongs to that assetId based on assetInfo and decalInfo
local function isTheDecal(assetInfo: productInfo, decalInfo: productInfo): boolean
local isDecal = (decalInfo.AssetTypeId == 13)
local sameCreator = (assetInfo.Creator.Id == decalInfo.Creator.Id)
return isDecal and sameCreator
end
local function assetToDecalId(assetId: number, lookAhead: number): number?
local assetInfo = getInfo(assetId)
if not assetInfo then error(assetId.." is not a valid assetId") end
for i = 1, lookAhead do
local decalId = assetId+i
local decalInfo = getInfo(decalId)
if decalInfo and isTheDecal(assetInfo, decalInfo) then return decalId end
end
return nil
end
print(assetToDecalId(assetId, lookAhead))
PS: This is the reverse of another known method for converting decal id to asset id, where the decal id is decreased by 1 until a match is found.