I want to make NPCs spawn in with different sets of clothes and have different genders. For some reason it is not working though. The script is parented to an NPC.
local s = script.Parent:FindFirstChildWhichIsA("Shirt")
local p = script.Parent:FindFirstChildOfClass("Pants")
local picker1 = math.random(1, 4)
if picker1 == 1 then -- blue suit female
s.ShirtTemplate = "http://www.roblox.com/asset/?id=6271127911"
p.PantsTemplate = "http://www.roblox.com/asset/?id=6279687903"
s.Color3 = Color3.new(255, 255, 255)
p.Color3 = Color3.new(255, 255, 255)
local femtorso = script.CharacterMesh:Clone()
femtorso.Parent = script.Parent
elseif picker1 == 2 then -- blue suit male
s.ShirtTemplate = "http://www.roblox.com/asset/?id=6271127911"
p.PantsTemplate = "http://www.roblox.com/asset/?id=6279687903"
s.Color3 = Color3.new(255, 255, 255)
p.Color3 = Color3.new(255, 255, 255)
elseif picker1 == 3 then -- green suit female
s.ShirtTemplate = "http://www.roblox.com/asset/?id=18883135239"
p.PantsTemplate = "http://www.roblox.com/asset/?id=18883142240"
s.Color3 = Color3.new(255, 255, 255)
p.Color3 = Color3.new(255, 255, 255)
local femtorso = script.CharacterMesh:Clone()
femtorso.Parent = script.Parent
elseif picker1 == 4 then -- green suit male
s.ShirtTemplate = "http://www.roblox.com/asset/?id=18883135239"
p.PantsTemplate = "http://www.roblox.com/asset/?id=18883142240"
s.Color3 = Color3.new(255, 255, 255)
p.Color3 = Color3.new(255, 255, 255)
end
What’s interesting is that the NPC will spawn with either male torso or female torso, so that part works. It’s just the clothes that don’t work.
local s = script.Parent:FindFirstChild("Shirt")
local p = script.Parent:FindFirstChild("Pants")
local outfits = {"Blue Suit (Female)",
"Blue Suit (Male)",
"Green Suit (Female)",
"Green Suit (Male)"
}
print("randomPick firing...")
local randomPick = math.random(1, #outfits)
print("Number of outfits is", #outfits)
print("randomPick finished...")
print(randomPick)
local chosenOutfit = outfits[randomPick]
print(chosenOutfit)
if chosenOutfit == "Blue Suit (Female)" then -- blue suit female
print("If chosenOutfit == 'Blue Suit (Female)' then")
s.ShirtTemplate = "http://www.roblox.com/asset/?id=6271127911"
p.PantsTemplate = "http://www.roblox.com/asset/?id=6279687903"
s.Color3 = Color3.new(255, 255, 255)
p.Color3 = Color3.new(255, 255, 255)
local femtorso = script.CharacterMesh:Clone()
femtorso.Parent = script.Parent
print("'If Blue Suit (Female)' section finished!")
elseif chosenOutfit == "Blue Suit (Male)" then -- blue suit male
print("If chosenOutfit == 'Blue Suit (Male)' then")
s.ShirtTemplate = "http://www.roblox.com/asset/?id=6271127911"
p.PantsTemplate = "http://www.roblox.com/asset/?id=6279687903"
s.Color3 = Color3.new(255, 255, 255)
p.Color3 = Color3.new(255, 255, 255)
print("'If Blue Suit (Male)' section finished!")
elseif chosenOutfit == "Green Suit (Female)" then -- green suit female
print("If chosenOutfit == 'Green Suit (Female)' then")
s.ShirtTemplate = "http://www.roblox.com/asset/?id=18883135239"
p.PantsTemplate = "http://www.roblox.com/asset/?id=18883142240"
s.Color3 = Color3.new(255, 255, 255)
p.Color3 = Color3.new(255, 255, 255)
local femtorso = script.CharacterMesh:Clone()
femtorso.Parent = script.Parent
print("'If Green Suit (Female)' section finished!")
elseif chosenOutfit == "Green Suit (Male)" then -- green suit male
print("If chosenOutfit == 'Green Suit (Male)' then")
s.ShirtTemplate = "http://www.roblox.com/asset/?id=18883135239"
p.PantsTemplate = "http://www.roblox.com/asset/?id=18883142240"
s.Color3 = Color3.new(255, 255, 255)
p.Color3 = Color3.new(255, 255, 255)
print("'If Green Suit (Male)' section finished!")
end
I’ve added a load of prints to make sure everything in the script is actually firing. And I’ve verified that this is true. I think the issue is purely a matter of the shirts/pants not loading/showing up for some reason.