I’ve been making a command to set a block’s decal. I’ve came across an issue that I’ve never encountered. The decal would not appear as the image I set in the args[1] (238316631), but when I set the image to my username, it appears. Can anyone help me with this issue?
--// 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 module = {}
function module.init(player, args)
-- just imagine args[1] being a player's username OR a decal ID
if args then
local imageProperty = nil
if tonumber(args[1]) then
print("DECAL ARGUMENT: NUMBER")
local ProductInfo = MarketPlaceService:GetProductInfo(tonumber(args[1]))
if ProductInfo.AssetId ~= nil then
if ProductInfo.AssetTypeId == 13 then
imageProperty = "rbxassetid://" .. args[1]
end
end
elseif tostring(args[1]) then
print("DECAL ARGUMENT: STRING")
local userId = game.Players:GetUserIdFromNameAsync(args[1])
if userId then
local imageContent, ready = game.Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.AvatarBust, Enum.ThumbnailSize.Size420x420)
imageProperty = imageContent
end
end
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].Texture = imageProperty
else
local inst = Instance.new("Decal")
inst.Parent = mouseTarget
inst.Name = mouseSurface.Name
inst.Face = Enum.NormalId[mouseSurface.Name]
inst.Texture = imageProperty
print(imageProperty)
end
end
end
end
end
return module
local MarketPlaceService = game:GetService("MarketplaceService")
local Events = game.ReplicatedStorage:WaitForChild("Events") -- Adjust according to your actual structure
function module.init(player, args)
if args then
local imageProperty = nil
if tonumber(args[1]) then
print("DECAL ARGUMENT: NUMBER")
local success, ProductInfo = pcall(function()
return MarketPlaceService:GetProductInfo(tonumber(args[1]))
end)
if success and ProductInfo then
print("ProductInfo retrieved successfully")
if ProductInfo.AssetTypeId == 13 then -- 13 corresponds to Decal
imageProperty = "rbxassetid://" .. args[1]
else
warn("The given AssetId does not correspond to a Decal")
end
else
warn("Failed to retrieve ProductInfo for AssetId:", args[1])
end
elseif tostring(args[1]) then
print("DECAL ARGUMENT: STRING")
local success, userId = pcall(function()
return game.Players:GetUserIdFromNameAsync(args[1])
end)
if success and userId then
local imageContent, ready = game.Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.AvatarBust, Enum.ThumbnailSize.Size420x420)
imageProperty = imageContent
else
warn("Failed to retrieve UserId for username:", args[1])
end
end
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].Texture = imageProperty
else
local inst = Instance.new("Decal")
inst.Parent = mouseTarget
inst.Name = mouseSurface.Name
inst.Face = Enum.NormalId[mouseSurface.Name]
inst.Texture = imageProperty
print("Decal applied with texture:", imageProperty)
end
else
warn("Failed to get target surface")
end
else
warn("Failed to get mouse target")
end
end
end
whether args[1] is a numeric asset ID or a username. Here are the changed lines:
Original: yours
local imageProperty = "rbxassetid://" .. args[1]
Updated: to see this
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
local userId = game.Players:GetUserIdFromNameAsync(args[1])
if userId then
local imageContent = game.Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.AvatarBust, Enum.ThumbnailSize.Size420x420)
imageProperty = imageContent
end
end
--// 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 module = {}
function module.SetDecal(player, args)
if args and #args > 0 then
local imageProperty = nil
-- Check if the argument is a numeric asset ID
if tonumber(args[1]) then
print("DECAL ARGUMENT: NUMBER")
local success, productInfo = pcall(function()
return MarketplaceService:GetProductInfo(tonumber(args[1]))
end)
if success and productInfo and productInfo.AssetTypeId == 13 then -- 13 corresponds to Decal
imageProperty = "rbxassetid://" .. args[1]
else
warn("The given AssetId does not correspond to a Decal")
end
-- Check if the argument is a username
elseif type(args[1]) == "string" then
print("DECAL ARGUMENT: STRING")
local success, userId = pcall(function()
return game.Players:GetUserIdFromNameAsync(args[1])
end)
if success and userId then
local imageContent, ready = game.Players:GetUserThumbnailAsync(userId, Enum.ThumbnailSize.Size420x420, Enum.ThumbnailType.HeadShot)
imageProperty = imageContent
else
warn("Failed to retrieve UserId for username:", args[1])
end
end
local mouseTarget = player.Character:FindFirstChild("HumanoidRootPart")?.Touched:InvokeClient(player, "target")
if mouseTarget then
local mouseSurface = player.Character:FindFirstChild("HumanoidRootPart")?.Touched:InvokeClient(player, "targetsurface")
if mouseSurface then
local decalPart = mouseTarget:FindFirstChild("Decal")
if decalPart then
decalPart.Texture = imageProperty
else
local decal = Instance.new("Decal")
decal.Parent = mouseTarget
decal.Texture = imageProperty
print("Decal applied with texture:", imageProperty)
end
else
warn("Failed to get target surface")
end
else
warn("Failed to get mouse target")
end
end
end
return module