I created a display system that allows users to input a decal ID and have it shown on several screens in a place. While scripting this, I have not found any reliable way to get the asset ID (to use in an ImageLabel) from a user-specified decal ID.
A workaround I have been using is to insert the decal ID into a thumbnail URL ( https://www.roblox.com/Thumbs/Asset.ashx?width=420&height=420&assetId=) and use the lower-resolution 420x420 thumbnail for the large display screens. I do not like using this workaround since the images are lower-resolution and the URL is not officially supported for use in games (as far as I know) and could be made useless at any time.
Another method would be to iterate through asset ID’s until you found the Image asset, but I’ve found that some ID’s can have up to 40 ID’s between them. This uses a lot of requests and can fail. There also has to be a limit, since it could go on forever in some cases.
The only officially supported way to do this currently is to use InsertService, but this would not be helpful in this case as InsertService only works for assets you own.
Unfortunately, It seems like getting the asset ID from a decal ID has been an issue for a long time.
What you mentioned about iterating through IDs will probably be your best bet. You can also possibly inform the player if there was an issue getting the asset ID from the decal ID.
This question has been asked so many times over. Please try searching before asking. I also feel bad for any poor soul who’s “iterated through Ids” or gone through the absolute frustration of subtracting numbers until you find the AssetId. Assets are uploaded to the site so fast that this just isn’t right.
There are APIs available in which you can use to get the ImageId for a Decal. You simply need to know its Library Id to extract its AssetId. The first known method is by getting its literal object from the InsertService. I’ve made a whack function that you could apply to your work on the fly.
local InsertService = game:GetService("InsertService")
local Decals = {} -- Whatever
local function ChangeDecalsToImages(Feed)
local ImageIds = {}
for _, Decal in pairs(Feed) do
local LiteralAsset = InsertService:LoadAsset(Decal):GetChildren()[1]
if LiteralAsset:IsA("Decal") then
table.insert(ImageIds, Decal.Texture)
end
end
return ImageIds
end
Decals = ConvertDecalsToImages(Decals)
The code above indexes the InsertService and holds a table of all your decals - these are the numbers that you see on a decal. Then, a function is created that takes a table of Ids, loads their literal object and confirms that they are of the Decal class. It then takes the Texture (ImageId) of the Decal and replaces that in the table, then returns a table. Below that, the Decals table is passed to the function before the Decals variable is reassigned to the return value of the function. I believe you’ll get strings from this instead of numbers, so all the better.
Next method I know is to use MarketplaceService::GetProductInfo on the Decal Id. Once you have this, you can simply index the AssetId and use that.
local MarketplaceService = game:GetService("MarketplaceService")
MarketplaceService:GetProductInfo(Id).AssetId --> bam, number
When using either of these methods, I would suggest wrapping them in protected calls. I don’t believe you have to, but from my understanding these are web calls and web calls can fail if servers or the site are down, thus resulting in your code throwing errors.
EDIT: There is an issue with the parsing of XML files. I will fix this issue in a few hours and update the post. This will be functional again very soon.
There is a google extension called “BetterRoblox” with just some advances, but it also makes getting an image-id from a decal as easy as clicking a button that brings you to the image page!
It also works for public domain assets if I recall correctly. The second method is adequate enough; this as well, I think I’ve already pitched a stance regarding InsertService and the usage of other people’s assets. It’s not that relevant though.
Only works for assets owned by the owner of the game and assets owned but Roblox. Not ones with public access. The reason InsertService is setup like that is to prevent stealing of models. You can only insert the owner’s models into their own game.