What exact link do u need for a decal to load through a script?

So i have this line of code, it works fine but the only part i have a question about is newTemplate.Image

Im trying to set the image to the link i put behind it, however when i playtest it it just stays blank?

Is this because of my code or because of the link i put in? Help would be appreciated!

for Index, Value in ipairs(Folder:GetDescendants()) do
	print(Value.Name)
	table.insert(Table, Value.Name)
	if Value.Name == "Garfield" then 
		local newTemplate = template:Clone()
		newTemplate.Name = "Garfield"
		newTemplate.Parent = scrollframe
		newTemplate.Image = "https://create.roblox.com/marketplace/asset/11882416957/Garfield"
		newTemplate.Visible = true		
newTemplate.Image = "rbxassetid://11882416957"

Still stays blank, could this have to do with the image? because it also stays blank if i put in that link manually

It’s most likely because it’s a decal ID and not an image ID. Here is a function that will convert a decal id to an image id.

Thats alot of code for loading in a simple image LMAO, isnt there any easier way?

There is another way that involves subtracting 1 from the decal ID until you reach the image, but this is super inefficient and will just end being more code. The shortest way to do this is paste the decal id into an image property, then copy the new id it creates, but that’s also super slow. If you easily wanna just do it through scripts then do this:

local InsertService = game:GetService("InsertService")
local MarketplaceService = game:GetService("MarketplaceService")

function getImageIdFromDecal(decalId: number)
	local assetInfo = MarketplaceService:GetProductInfo(decalId, Enum.InfoType.Asset)
	
	assert(assetInfo.IsPublicDomain)
	assert(assetInfo.AssetTypeId == Enum.AssetType.Decal.Value)
	
	local decal = InsertService:LoadAsset(decalId):FindFirstChildWhichIsA("Decal")
	return decal.Texture
end

print(getImageIdFromDecal(3339338289))

Keep in mind the above is a function, therefore you can use it multiple times with different ID’s.

getImageIdFromDecal(3339338289)
getImageIdFromDecal(11882416957)
...etc.

I think its the only way so thats fine, but right now when i try to use it i get this error.

image

Your decal is probably not public, here is a fix for this:

local InsertService = game:GetService("InsertService")
local MarketplaceService = game:GetService("MarketplaceService")

function getImageIdFromDecal(decalId: number)
	local assetInfo = MarketplaceService:GetProductInfo(decalId, Enum.InfoType.Asset)

	assert(assetInfo.AssetTypeId == Enum.AssetType.Decal.Value)
	
	local decal = InsertService:LoadAsset(decalId):FindFirstChildWhichIsA("Decal")
	return decal.Texture
end

print(getImageIdFromDecal(3339338289))
1 Like

This works indeed, thanks!.

Also found myself another solution, in which i got a better resolution picture: It's Impossible to Get an Image ID From a Decal ID - #25 by Awes_3

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.