NPC Randomize clothes system

I’m trying to randomize an NPC’s clothing, and it just keeps on making my NPC not have any clothes, everything else that’s apart of the script works fine, just not the clothes part. Here is my script below.

	188003563,13655562,4735347390,4735346175}

local faceacc = {5355727732,5355564336,4510537113,4528880486,74970669,4507911797,4102114619,987022351,
	4904398878,5063784744,4708784614}

local facial = {158066137,4995497755,987022351,5231324178,4940496302,4786863817,4524490255,5197016342}

local shirts = {15182204979,13367253189,12619102033,71471392,5455528428}

local pants = {9266897337,6028423765,5617080014,6915386269}

local marine = script.Parent.Parent.Parent

function applyAsset(id)
	local item = game:GetService("InsertService"):LoadAsset(id)
	local items = item:GetChildren()
	local accessory = items[1]
	local handle = accessory.Handle
	
	accessory.Parent = marine
	item:Destroy()
	
	task.wait()
	
	handle.Parent = marine
	handle.Name = id
	
	accessory:Destroy()
	
	local weld = Instance.new("WeldConstraint")
	weld.Part0 = marine.Head
	weld.Part1 = handle
	weld.Parent = handle
end

if script.Parent.Parent.Parent.Settings.RandomAppearance.Value then
	if math.random(8) == 1 then
		applyAsset(facial[math.random(#facial)])
	end
	
	if math.random(8) == 1 then
		marine.Head.goggles:Destroy()
		applyAsset(faceacc[math.random(#faceacc)])
	end

	if math.random(11) == 1 then
		marine.ACH:Destroy()
		applyAsset(hair[math.random(#hair)])
	end
	
	if math.random(1) == 1 then
		script.Parent.Parent.Parent.Shirt.ShirtTemplate = (shirts[math.random(#shirts)])
	end
	
	if math.random(1) == 1 then
		script.Parent.Parent.Parent.Pants.PantsTemplate = (pants[math.random(#pants)])
	end

	local skinOptions = {"Wheat","Cashmere","Beige","Light orange","Buttermilk","Pastel yellow"}
	local randomSkin = BrickColor.new(skinOptions[math.random(#skinOptions)])
	local bc = marine["Body Colors"]
	bc.HeadColor = randomSkin
	bc.LeftArmColor = randomSkin
	bc.RightArmColor = randomSkin
	bc.LeftLegColor = randomSkin
	bc.RightLegColor = randomSkin
	bc.TorsoColor = randomSkin
end

Looks like youre using math.random incorrectly

math.random(min,max) returns a random number between min and max. Try changing the, to math.random(1,8) and do the same for the rest

The other accessories all work, but not the clothes

try change HumanoidDescription instead of change shirt instance id ,like this,btw i noticed some id are not working im not sure is this my problem
image


	if math.random(1) == 1 then
		local hmd = marine.Humanoid:GetAppliedDescription()
		hmd.Shirt = (  shirts[math.random(#shirts)])
 		marine.Humanoid:ApplyDescription(hmd)
	end
1 Like

188003563,13655562,4735347390,4735346175}

local faceacc = {5355727732,5355564336,4510537113,4528880486,74970669,4507911797,4102114619,987022351,
4904398878,5063784744,4708784614}

local facial = {158066137,4995497755,987022351,5231324178,4940496302,4786863817,4524490255,5197016342}

local shirts = {15182204979,13367253189,12619102033,71471392,5455528428}

local pants = {9266897337,6028423765,5617080014,6915386269}

local marine = script.Parent.Parent.Parent

function applyAsset(id)
local item = game:GetService(“InsertService”):LoadAsset(id)
local items = item:GetChildren()
local accessory = items[1]
local handle = accessory.Handle

accessory.Parent = marine
item:Destroy()

task.wait()

handle.Parent = marine
handle.Name = id

accessory:Destroy()

local weld = Instance.new("WeldConstraint")
weld.Part0 = marine.Head
weld.Part1 = handle
weld.Parent = handle

end

if script.Parent.Parent.Parent.Settings.RandomAppearance.Value then
If
if math.random(8) == 1 then
applyAsset(facial[math.random(#facial)])
end

if math.random(8) == 1 then
	marine.Head.goggles:Destroy()
	applyAsset(faceacc[math.random(#faceacc)])
end

if math.random(11) == 1 then
	marine.ACH:Destroy()
	applyAsset(hair[math.random(#hair)])
end

if math.random(1) == 1 then
	script.Parent.Parent.Parent.Shirt.ShirtTemplate = (shirts[math.random(#shirts)])
end

if math.random(1) == 1 then
	script.Parent.Parent.Parent.Pants.PantsTemplate = (pants[math.random(#pants)])
end

local skinOptions = {"Wheat","Cashmere","Beige","Light orange","Buttermilk","Pastel yellow"}
local randomSkin = BrickColor.new(skinOptions[math.random(#skinOptions)])
local bc = marine["Body Colors"]
bc.HeadColor = randomSkin
bc.LeftArmColor = randomSkin
bc.RightArmColor = randomSkin
bc.LeftLegColor = randomSkin
bc.RightLegColor = randomSkin
bc.TorsoColor = randomSkin

end

My bad, I made an error

Ihateribloxlimits

I think this should work.

188003563,13655562,4735347390,4735346175}

local faceacc = {5355727732,5355564336,4510537113,4528880486,74970669,4507911797,4102114619,987022351,
	4904398878,5063784744,4708784614}

local facial = {158066137,4995497755,987022351,5231324178,4940496302,4786863817,4524490255,5197016342}

local shirts = {15182204979,13367253189,12619102033,71471392,5455528428}

local pants = {9266897337,6028423765,5617080014,6915386269}

local marine = script.Parent.Parent.Parent

function applyAsset(id)
  local item = game:GetService("InsertService"):LoadAsset(id)
  local items = item:GetChildren()
  local accessory = items[1]
  local handle = accessory.Handle
  
  accessory.Parent = marine
  item:Destroy()
  
  task.wait()
  
  handle.Parent = marine
  handle.Name = id
  
  accessory:Destroy()
  
  local weld = Instance.new("WeldConstraint")
  weld.Part0 = marine.Head
  weld.Part1 = handle
  weld.Parent = handle
end

if script.Parent.Parent.Parent.Settings.RandomAppearance.Value then
  local randomnum = math.random(1, 11)
  if randomnum == 1 then
    applyAsset(facial[math.random(1, #facial)])
  elseif randomnum == 2 then
    marine.Head.goggles:Destroy()
    applyAsset(faceacc[math.random(1, #faceacc)])
  elseif randomnum == 3 then
    marine.ACH:Destroy()
    applyAsset(hair[math.random(1, #hair)])
  elseif randomnum == 4 then
    script.Parent.Parent.Parent.Shirt.ShirtTemplate = (shirts[math.random(1, #shirts)])
  elseif randomnum == 5 then
    script.Parent.Parent.Parent.Pants.PantsTemplate = (pants[math.random(1, #pants)])
  
  
  local skinOptions = {"Wheat","Cashmere","Beige","Light orange","Buttermilk","Pastel yellow"}
  local randomSkin = BrickColor.new(skinOptions[math.random(1, #skinOptions)])
  local bc = marine["Body Colors"]
  bc.HeadColor = randomSkin
  bc.LeftArmColor = randomSkin
  bc.RightArmColor = randomSkin
  bc.LeftLegColor = randomSkin
  bc.RightLegColor = randomSkin
  bc.TorsoColor = randomSkin
end

It works, but it sometimes just makes the shirt id, http://www.roblox.com/asset/?id=855777285, and that makes the NPC have those weird Roblox clothes you get while having no clothes on.
image