NPC Outfit Randomizer Not working as expected

Hello there devs! I’ve been working on an outfit randomizer for NPCs.

I could say it works, but the shirt and pants don’t change.

So when I test it, the shirt and pants id changes as you can see in the picture.
image

Everything seems to be good. But when you look at the NPCs, they don’t have clothes textures.
image

The script:

--local Hats = {"rbxassetid://62246484", "rbxassetid://3993078764", "rbxassetid://20372960", "rbxassetid://158066137", "rbxassetid://16630147", "rbxassetid://398672568", "rbxassetid://451221329", "rbxassetid://47702745"}

local Shirts = {"rbxassetid://607785314", "rbxassetid://1210857662", "rbxassetid://1821394", "rbxassetid://5692395530", "rbxassetid://6959669630", "rbxassetid://3599544679","rbxassetid://4008790623", "rbxassetid://7211566453"}

local Pants = {"rbxassetid://129459077", "rbxassetid://398633812", "rbxassetid://129458426", "rbxassetid://4628693536", "rbxassetid://7552948186", "rbxassetid://5672931884", "rbxassetid://144076760", "rbxassetid://5933262354"}

wait(1)

local RandomShirt = Shirts[math.random(1, #Shirts)]
local RandomPants = Pants[math.random(1, #Pants)]
--local RandomHats = Hats[math.random(1, #Hats)]


script.Parent.Shirt.ShirtTemplate = RandomShirt
script.Parent.Pants.PantsTemplate = RandomPants
--script.Parent.Hat.Handle.Mesh.MeshId = RandomHats

Ignore the “hats part”.

Any help is appreciated :smiley:

1 Like

What instance type is that in the first screenshot?

I selected both “Shirts” and “Pants”, they’re two different instances.

Those are the properties what is the selected instance in explorer?

image

I see now, you’re attempting to use the clothing’s ID as opposed to the actual asset ID of the clothing.

This is the asset of the first shirt.

You’ll need to go through all of the clothing ID’s and replace them with the asset ID’s instead.

local Shirts = {"607785311", "1210857659", "1821393", "5692395502", "6959669627", "3599544640","4008790580", "7211566446"}

local Pants = {"129459076", "398633811", "129458425", "4628693524", "7552948161", "5672931834", "144076759", "5933262332"}

wait(1)

local RandomShirt = Shirts[math.random(1, #Shirts)]
local RandomPants = Pants[math.random(1, #Pants)]
--local RandomHats = Hats[math.random(1, #Hats)]


script.Parent.Shirt.ShirtTemplate = "http://www.roblox.com/asset/?id="..RandomShirt
script.Parent.Pants.PantsTemplate = "http://www.roblox.com/asset/?id="..RandomPants

I’ve decided to do it for you.

1 Like

Thank you so much for the answer, it really helped me :slight_smile:

Thanks :smiley:

No problem, for a quick and easy way to get the template ID of a clothing ID you can do the following in studio:

https://gyazo.com/7b5d6310a3a15841f9d6ef2dced24d13
Notice how the ID changes?

1 Like

Yeah! Now I understand it. Thank you very much :grinning_face_with_smiling_eyes:

I know i might be 3 years late but oh my god thank you so much for this!