Applying decal via script issue (not displaying in-game)

I’m making a simple game for coding practice. In this game, you can spawn a Sphere part and can arbitrarily give it special properties. An issue I am running into is with applying a Decal to a part, and having it be visible in-game.

Through Studio, spawning in a Part, adding the Decal instance, and adding an ID to the Texture property displays the decal correctly. However, the same does not apply when trying it through Script.

Attempting:

--robloxID is an integer
decal.Texture = robloxID 

or

decal.Texture = tostring(robloxID) 

or

decal.Texture = "http://www.roblox.com/asset/?id=" .. tostring(robloxID)

or

local idLink = "http://www.roblox.com/asset/?id=%s"
decal.Texture = (string.format(idLink, tostring(robloxID))

has no effect, even though the ID is valid.

I could only get the decal to display when copying it from a pre-existing part:

decal.Texture = workspace.getDecal.PreTexturedPart.Decal.Texture

However, this is unideal because I want decals to be arbitrarily created and inserted, not pre-created and pre-inserted. Is there any way to allow my system to work?

I know that the function itself works because it prints the correct ID when I run it, and it displays the correct string in the Decal instance itself when inspecting it via the workspace while my game is running.

Any help would be appreciated!

2 Likes

If you want to know what the correct idlink format is you can paste the ID into a decal using the properties window! I believe it is:

"rbxassetid://" .. id

After verifying if this is the correct prefix, setting the ID should be as easy as:

decal.Texture = string.format("rbxassetid://%i", robloxID)

Disclaimer: There may be issues with code provided above as I have not double checked in studio if this is correct or not.

1 Like

No luck, the decal is still read, but invisible. :frowning:
I tried a few variations, such as:

decal.Texture = string.format("rbxassetid://%s", robloxID)
decal.Texture = string.format("http://www.roblox.com/asset/?id=%i", robloxID)
decal.Texture = string.format("http://www.roblox.com/asset/?id=%s", robloxID)

as well as changing each variant of “robloxID” to “tostring(robloxID)”, but that didn’t work either. I checked the Texture property and the value does display correctly, the decal itself just doesn’t show up in-game for some reason.

Would you be able to send link to the asset you are trying to use as a decal?

https://create.roblox.com/marketplace/asset/6886240598/8-ball-TEXTURE?pageNumber=1&pagePosition=1&keyword=8-ball

It does display when I applied the decal in Studio and when manually applying the decal’s ID while using Test Mode in Studio, just not through Script.

i thought it was

Decal.Texture = "rbxassetid://000000"

Doing

script.Parent.Decal.Texture = string.format("http://www.roblox.com/asset/?id=%i", 6886240593)

works perfectly fine for me with the following layout:
image

Have you tried printing robloxID to make sure that the ID is supplied properly? Have you also verified that the correct decal.Face is selected?

@sussy_bacoo So did I, but it seems that is not for decals, but it is for images in UI.

EDIT: After re-reading your post I noticed that you had a sphere. In that case it seems that “rbxassetid://” is the correct prefix. The following code worked for me, with the same layout as pictured above.

script.Parent.Decal.Texture = string.format("rbxassetid://%i", 6886240593)

Though I need the Decal ID to be arbitrarily applied as the ID gets passed through a function, so I sadly can’t use that method of having it be pre-written regardless :frowning:

what if you make a brand new decal instead of changing a single one

local decal = Instance.new("Decal")
			decal.Parent = workspace.part
			decal.Texture = (texture)
			decal.Face = Enum.NormalId.Top

It works, I think! Still tinkering around with a few things, it worked when I copied the same line into my pre-existing script thankfully, but overall the texture does display now. Thank you!

1 Like

Wait, I need to double-check this real quick. I accidentally left another line in there which may be adding the texture instead…

Yeah, this works! Just stopped working when I retried it in my current script. Again, no idea why. I’ll probably have to rewrite some stuff to account for this method, but I appreciate this solution. Thank you :slight_smile:

If you need some help fitting this in somewhere just let me know and I’ll be happy to help you out. :smile:

Once your issue has been resolved, don’t forget to mark the solution as a solution!

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