Changing decal texture with code isn't working

So I’m trying to change the texture of a decal like this:

for i,decal in pairs(Model:GetChildren()) do
	if decal:IsA("Decal") then
		decal.Texture = "rbxassetid://"..TextureID
	end
end

But it doesn’t change its texture. I have looked at the decal and it applied the right texture but it just didn’t change its look. I’ve also tried it with “http://www.roblox.com/asset/?id=”…TextureID but this also didn’t change anything. But when I paste the id in their myself it works.

1 Like

Hi! I tried to replicate something similar so I did the following:

  1. I tagged the decal with a “Decal” Tag, then used CollectionService to call the objects. I think this is better as you can tag a lot of decals, and change specific ones with little code

  2. The code (in ServerScriptService):

local CollectionService = game:GetService("CollectionService")
local TextureID = [MUST BE AN INTEGER]

for i,decal in pairs(CollectionService:GetTagged("Decal")) do
	if decal then
		print("Changing Decal!")
		decal.Texture = "rbxassetid://"..TextureID
	end
end

What if you have many decals?

Suppose you have 3 decals, if we did the following:

local CollectionService = game:GetService("CollectionService")
local TextureID = [MUST BE AN INTEGER]

for i,decal in pairs(CollectionService:GetTagged("Decal")) do
	if tostring(decal) == "Decal1" then
		print("Changing Decal!")
		decal.Texture = "rbxassetid://"..TextureID
    elseif tostring(decal) == "Decal2" then
print("Changing Decal!")
		decal.Texture = "rbxassetid://"..TextureID
    elseif tostring(decal) == "Decal3" then
print("Changing Decal!")
		decal.Texture = "rbxassetid://"..TextureID
	end
end

This can be very messy very quick, so instead we can pair by index:

local CollectionService = game:GetService("CollectionService")

local Textures = {
	[Number for texture 1],
	[Number for texture 2 (remove the brackets!)],
    [Number for texture 3]
}

for i,decal in pairs(CollectionService:GetTagged("Decal")) do
	if decal then
		print("Changing Decal!")
		decal.Texture = "rbxassetid://"..Textures[i]
	end
end

I hope this helps!

1 Like

My problem is not changing the Texture of more then 1 decal my problem is that the texture doesnt change at all

1 Like

trying to record a video of the problem atm

I understand, I think the tagged method should still work as you can call tagged objects from ServerScriptService, and I think is an easier method than getting a model’s children and going through them. By tagging them, you know each decal you tag will be a decal so you can avoid doing decal:IsA"Decal"!

Video of the problem:

Interesting, so I will confirm that the issue is not with the specific piece of code sent over as I made a part with a decal and was able to change the decal with the given method. I don’t think you did anything wrong with the implementation of the textureID, have you tried publishing it to Roblox first, then checking within a Roblox game to see if it is a Studio bug perhaps?

Code I used:

local Texture = [MUST BE AN INTEGER]
local Model = workspace:WaitForChild("TestingDecal")

for i,decal in pairs(Model:GetChildren()) do
	if decal:IsA("Decal") then
		decal.Texture = "rbxassetid://"..Texture
	end
end

Could you send a copy of your game file? I think I know what the issue is, but I want to try the fix before I respond.

Mhm I tried doing it in the “real” game but it also doesn’t work there.

Was there a solution to this? I’m having problems with the same thing too.

I’m attempting to use decals available in the marketplace store with no success. I’ve used the same precursors as you had in the original post, but I also tried "https://create.roblox.com/store/asset/"..id

None of these worked successfully with various IDs.

Nope still didn’t have a solution for that.

Unfortunate, I’ll keep my eyes peeled for other posts that crop up! Wonder if it’s something to do with a new feature added in recently made games, like for example how newer games have streamingenabled properties :thinking:

1 Like

Hello, sorry for deleting my previous response.
Is the “Model” in this case, the pillow tool or handle?

Because if it’s the tool, then try using :GetDescendants()
If it’s the handle, then there really should not be any problems.

Video Demonstration:

I believe I found the reason:

Basically, it’s way more complicated than it should be. For some reason, decals and images are different things and you have to reference the image

Some people mention using HTTP requests and others mention removing one from the ID, getting game.MarketPlaceService:GetProductInfo(“Creator”) and checking to see if the creator is the same as the original ID. I quickly threw together some code for the latter:

local function findimage(creatorinfo, decalid)
	local currentid = decalid
	
	for i = 1,2000 do		
		currentid -= 1
		 		 
		local newinfo = game.MarketplaceService:GetProductInfo(currentid)["Creator"]
				 
		if newinfo["Id"] == creatorinfo["Id"] then
			return currentid
		end
	end
end

(where creatorinfo = game.MarketplaceService:GetProductInfo(decalid)[“Creator”])

This method appears to be ludicrously slow however. Much better to use http requests I reckon- It’s what F3X uses for their decal system.

I’ve not tried this, but I believe if it’s your own asset you can use InsertService:LoadAsset()?

1 Like

Wow that’s just so complicated for something so simple. Thanks anyways!

1 Like