Answered by
5 years ago Edited 5 years ago
Explanation
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.
Solution
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.