TLDR: How can I convert the decal’s ID to the image of an image button effectively? Like how can I make a large amount of decals into image buttons solely from a script?
I’m trying to create a plugin with tens of thousands of user interfaces, and to do that I’ll need a lot of icons. And to speed up the process I can select all of my icons from the asset manager and insert them into the workspace.
But my problem is that when they are added, they are decals, and I’m wondering how I can convert the decals to an image label effectively. Because manually doing it would take a very long time.
If somebody could provide me with a base script, a developer forum post, or anything else, I’d be very appreciative.
Any other information will be provided if you ask.
There’s two types of image references: Decals & Images. Decals and Images have different IDs, and Decals are for… well, Decals (or textures), but Images are for UI. The thing about this is that the IDs differ due and you can’t “calculate” the ID, the way Roblox does it (I’m assuming, but is most likely) is just grabbing it off a database.
You could loop through all the decals and grab the texture property and then create a new ImageButton and set the Image property to the texture property.
for index, value in pairs(decals:GetChildren()) do
if value:IsA("Decal") then
local iButton = Instance.new("ImageButton")
iButton.Image = value.Texture
iButton.Parent = screengui
iButton.Size = Udim2.new(0.1, 0, 0.1, 0)
end
end
Here is essentially what you would do. You need to .Parent it to a screengui and add a .Size property for them to appear inside a screengui, but this is the barebones.
This is also assuming you have all your decals inside a folder and referenced the folder somewhere in the script.
I would like to point out whilst this does work in one instance, and I was incorrect with this
I was correct in displaying the difference between Decal & Image IDs and how because they can differ this solution will not always work with slightly different circumstances! Thankfully ImageButtons & Decals share the same texture method.