Ok so now I have a serverscript inside of a part with the click detector and the id value. The instance is in the character, but doesn't display on the character.
local part = script.Parent local detector = part.ClickDetector local id = part.Id clothingType = "Pants" --Change to "Pants" or "Shirt" detector.MouseClick:Connect(function(player) if player.Buy.Value == true then else local char = workspace:FindFirstChild(player.Name) local findClothing = char:FindFirstChild(clothingType) if findClothing then findClothing:Destroy() if clothingType == "Shirt" then local newShirt = Instance.new("Shirt") newShirt.Name = "Shirt" newShirt.ShirtTemplate = "http://www.roblox.com/asset/?id="..id.Value newShirt.Parent = char elseif clothingType == "Pants" then local newPants = Instance.new("Pants") newPants.Name = "Pants" newPants.PantsTemplate = "http://www.roblox.com/asset/?id="..id.Value newPants.Parent = char end else if clothingType == "Shirt" then local newShirt = Instance.new("Shirt") newShirt.Name = "Shirt" newShirt.ShirtTemplate = "http://www.roblox.com/asset/?id="..id.Value newShirt.Parent = char elseif clothingType == "Pants" then local newPants = Instance.new("Pants") newPants.Name = "Pants" newPants.PantsTemplate = "http://www.roblox.com/asset/?id="..id.Value newPants.Parent = char end end end end)
The issue isn't with your script, but with what you place into the ID value. When a piece of clothing is created, there are actually two assets created. Not only is your clothing (in the form of an XML file) uploaded, but an image of your clothing is also uploaded.
Whenever you add clothes to a character in-game, Roblox expects you to place the image ID into the Template property, which is why it errors when you use the clothing ID. It's attempting to read the XML file as an image at runtime, which ends up throwing an error.
Before doing any of this, make sure to install BTRoblox.
In order to get an image ID from a piece of clothing, click on the piece of clothing you want to add into your game. Right next to the name of the clothing, there should be an icon that resembles a photograph. Clicking on it should send you to the library page for the image, which you can then get the ID of from the URL.
EDIT: I know this answer is not about scripting, but it's still some important information that not many people know about.
EDIT 2: Here's proof your script works. I used the same script as shown in the question, and the only thing I changed was the ID value.