Getting a Decal's AssetID In-game

so, this is a pretty common question from what i searched. i’ve had this issue before andi had it solved. however, it seems like previous solutions doesn’t work completely reliably anymore.
the old workaround from years ago was to subtract 1 from the catalog ID. then, that wasn’t enough, so a new workaround was using MarketplaceService to find the assetid isntead. however, that stopped being able to be used due to HTTPs timeouts. and assetids usually being 100+ different numbers away from their decalid.

what’s a good way to fix this? for context, users are going to paste in an ID they found from catalog to morph into, since that’s what most users tend to do. i don’t want them to rely on some website plugin, i want the game itself to do it.

3 Likes

To accomplish this, I use rprxy.xyz. To get the image id, you can use the following function:

local function getImageId(assetId)
	return pcall(function()
		local res = game.HttpService:GetAsync('https://assetdelivery.rprxy.xyz/v1/asset/?id='..assetId)
		if res then
			return res:match('(%d+)</url>')
		end
	end)
end
Usage Example
local decalId = 4275614727 -- Insert your decal id here

local success,result = getImageId(decalId)
if not success then
	-- Put code to run if the image is properly returned here
	print('Image ID:',result)
else
	-- Put code to run if no image exists here
	print('Failed to get image ID with error:',result)
end

Disclaimer: I didn’t create this function. You can find the original post where I got it here.

Also, as noted in the linked post, this might be rather slow and unreliable if you’re using this for a larger game. You should consider hosting the open source proxy privately if you would like to avoid this.

5 Likes

Decals are technically stored like models on site. You can use InsertService:LoadAsset(decalId) which should give you a Decal instance. Then you can get the Texture property of the decal and extract the numeric id like so: local imageId = tonumber(decal.Texture:match("%d+"))

Edit: See below

1 Like

This is already supported. Use rbxthumb to display Decals easily. No more need to get the image id to display it!

Release thread: New ContentId format for easy thumbnail loading

7 Likes

Somehow I managed to completely forget this existed! This is definitely the best answer here and isn’t hacky at all (in fact its intended to be used that way) so I think it should be marked as the solution over the others.

i was considering this, but i dont really want to use thumbnails since they often feel a bit less high quality for me. will look into this though!

edit: it seems it only supports images being square, nothing else. that’s not exactly something i can work with i feel.

i like this workaround, but i’d like to be able to insert decals that the person don’t necessarily own, too. though if worse comes to worse this works as well