How can I get a texture id from a decal id?

I’m making something similar to the spray can and I’d like to include an image preview. I’m unsure of how to get a texture id from a decal asset. I’ve tried taking the Id and subtracting 1, which works for old decals but not new ones. I’d like to avoid having to use the texture Id as it’s fairly difficult to get for an end user (having to launch studio, add the decal to their scene, copying and pasting the id). What’d work even better is if it was possible to make the decals searchable in game somehow, but that would probably be a whole issue on it’s own.

1 Like

You should just be able to paste the whole decal link and should get the ID automatically.

I believe you can just set the TextureId to the complete asset URL as you would use to find the asset on the website.

This appears to work in Studio but not in code.
The following line errors:

workspace.Part.Decal.Texture = "https://www.roblox.com/library/127035411/Deluxe-Ninja-Swordpack"

However pasting the url functions as you said it would

1 Like

Huh, odd, I could’ve sworn it worked in a live game.

You can’t get the TextureId with 100% accuracy without using HttpService and a web host which downloads the decal and then reads the TextureId from it. You could make a loop which descends the ID until a few conditions are met, yet there would be complications with group decals if you checked for the CreatorId or if someone creates multiple decals simultaneously and the IDs kind of mix up.

I recommend using the decal thumbnail instead. If 420x420 is enough of resolution for you, I’d use that since thumbnails are mostly already generated in that resolution, preventing the blank image from showing up and caching on clients before it’s been generated.

Try using

Decal.Texture = "https://www.roblox.com/Thumbs/Asset.ashx?width=420&height=420&assetId=" .. decalIdHere
10 Likes

That works great! Thanks

1 Like

Better late than never.