Loading clothing onto NPCs from a script?

How do I make a script load clothing on an NPC? When you put the catalog clothing ID in the ShirtTemplate or PantsTemplate property of a clothing object in studio, it automatically changes it to the source template for that shirt. How would I do that with a script?


Have you tried setting the ShirtTemplate property from the script?

Yes. Of course. But the ShirtTemplate property needs to be set to the actual shirt template, when you set it to the shirt catalog ID in studio, it automatically changes that ID to the shirt template ID.

You can do this yourself as well.
You would simply do:

local ShirtID = [ID OF SHIRT]
local PantsID = [ID OF PANTS]

Character.Pants.PantsTemplate = "http://www.roblox.com/asset/?id=" .. PantsID 
Character.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id=" .. ShirtID 

I just tested it in my game, and it worked:

That’s because you’re setting it to the library template ID. I want the script to be able to find the template ID from the catalog ID.

The catalog ID and the template ID are not the same… When you paste the catalog ID into the ShirtTemplate property, it automatically changes it to the library template ID.

Ah yes, I realised afterwards; my bad.

Thanks anyways.

(the rest of the thirty characters)

You can retrieve the template ID by using InsertService.
InsertService:LoadAsset(catalogId) returns a model containing whatever asset you load. In this case, it will return a model containing a Shirt. From that Shirt you can extract the ShirtTemplate.


You can use InsertService in that case:

local InsertService = game:GetService("InsertService")
local ShirtID = 5025324849 -- ID from catalog
local model = InsertService:LoadAsset(ShirtID) -- it inserts it as a model
model.Shirt.Parent = Character -- Or just get the model.Shirt.ShirtTemplate and set the Character's ShirtTemplate to that

More on InsertService: InsertService | Documentation - Roblox Creator Hub


Ah, you beat me to it; sorry I didn’t see your post til after I posted.