Setting a Decal

I’ve been working on a building game that has commands, similar to blockate. I’ve been trying to make a command that creates decals onto a block’s surface. So far, I’ve got the function working, but the decal (the id is 11201552339) would not set itself.

I’ve tried rbxassetid:// and http://www.roblox.com/asset/?id=, but both of them did NOT work at all.

My current code:

--// Services
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local MarketPlaceService = game:GetService("MarketplaceService")

--// Variables
local Events = ReplicatedStorage:WaitForChild("Events")

local CommandsEvent = Events:WaitForChild("Commands")
local CommandMessage = CommandsEvent:WaitForChild("CommandMessage")

local ExtraArguments = {
	"rotation",
}

local module = {}

function module.init(player, args)

	if args then

		local ExtraArg = nil
		local imageProperty = nil
		if tonumber(args[1]) then
			
			local ProductInfo = MarketPlaceService:GetProductInfo(tonumber(args[1]))
			if ProductInfo and ProductInfo.AssetTypeId == 13 then
				
				imageProperty = "rbxassetid://" .. args[1]
				
			end
			
		else
			
			if not table.find(ExtraArguments, string.lower(args[1])) then
				
				local userId = game.Players:GetUserIdFromNameAsync(args[1])
				if userId then

					local imageContent = game.Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.AvatarBust, Enum.ThumbnailSize.Size352x352)
					imageProperty = imageContent

				end
				
			else
				
				ExtraArg = string.lower(args[1])
				
			end
			
		end
		
		if ExtraArg == nil then
			
			if imageProperty ~= nil then

				local mouseTarget = Events.GetTarget:InvokeClient(player, "target")
				if mouseTarget then

					local mouseSurface = Events.GetTarget:InvokeClient(player, "targetsurface")
					if mouseSurface then

						CommandMessage:FireClient(player, "SUCCESSFULLY MADE DECAL!")

						if mouseTarget:FindFirstChild(mouseSurface.Name) then

							mouseTarget[mouseSurface.Name].Decal.Texture = imageProperty

						else

							local clone = mouseTarget:Clone()
							clone.Name = mouseSurface.Name
							clone.Parent = mouseTarget
							clone.CanCollide = false
							clone.CanQuery = false
							clone.Transparency = 1

							local inst = Instance.new("Decal")
							inst.Face = Enum.NormalId[mouseSurface.Name]
							inst.Texture = imageProperty
							inst.Parent = clone

						end

					end

				end

			end
			
		else
			
			if ExtraArg == "rotation" then
				
				print(args[2])
				if args[2] and tonumber(args[2]) then
					
					local mouseTarget = Events.GetTarget:InvokeClient(player, "target")
					if mouseTarget then

						local mouseSurface = Events.GetTarget:InvokeClient(player, "targetsurface")
						if mouseSurface then

							if mouseTarget:FindFirstChild(mouseSurface.Name) then

								mouseTarget[mouseSurface.Name].CFrame *= CFrame.Angles(0, math.rad(args[2]), 0)

							end

						end

					end
					
				end
				
			end
			
		end

	end

end

return module

If you are attempting to help me, please include explanations.

1 Like

Roblox is weird and changes the ID to something else. Try using this ID instead: 11201552325.

1 Like

Question, where did u get the ID?
Edit: The ID did not work either.

I’m just a professional gamer. I inserted the ID into the decal, and it returned this: http://www.roblox.com/asset/?id=11201552325

Well damn.

1 Like

Yeah, that works when u set the Decal through the workspace, but not through script.

It works fine for me when I run it through a script?

script.Parent.Decal.Texture = "rbxassetid://11201552325

1 Like

This is what im doing

imageProperty = "rbxassetid://" .. tostring(args[1])

I mean I did mention that Roblox is weird. Are there any errors?

1 Like

Nope, no errors are occuring, just the decal not appearing.

Is the decal’s face property assigned correctly?

1 Like

Yes, I’ve tested it in studio and in-game.

Weird thing for you to use tostring(...). Try changing it to a tonumber(...). IDs are numbers, not strings. :wink:

1 Like

It works fine for me, don’t think that’s the issue.

Also wait, I’ve just realized. Decal’s texture property requires a URL, and for some reason when you do it via scripts it doesn’t convert it into one. So tonumber() is pointless for this.

1 Like

That still did not work sadly…

I get your point, but the main deal here is that if they want to use args[1] as a number, the best practice is to alter tostring() to a tonumber() call.

1 Like

Try yeeting some debugging in your codes to see where the grand error is. Debugging is simple, just add print() statements in critical portions of the program.

1 Like

Well, there aren’t any errors, and I have chat message occur when the command function is completed running. And it shows the message every time, so the error is the decal not setting.

IDs are strings.

An example of an ID is rbxassetid://12345678. How would you add the rbxassetid:// without it being a string? The rest is a number, but the prefix isn’t. You can’t put strings into numbers, but you can put numbers into strings.

1 Like

You’re probably using the wrong ID.

Use the Decal ID. In this case, it is http://www.roblox.com/asset/?id=11201552325 or rbxassetid://11201552325.

1 Like

Heres the thing, the ‘rbxassetid://’ string is being concacenated with args[1] or in this case, 11201552325.

"rbxassetid://" .. args[1]