I made a module script that spawns a random NPC every few minutes, and everything works except I can't seem to get the NPC to have a hair I want equipped. I try InsertService and everything, nothing seems to work.

Portion of the module;

function System.new(ntype,nspawn,chat,cameraangle)
	local play = game.Players.LocalPlayer
	local char = play.Character or play.CharacterAdded:wait()
	local cam = workspace.CurrentCamera
	local gui = play:WaitForChild("PlayerGui")
	local cd = false
	
	-- Spawning
	local gen = math.random(1,2)
	local npc = Templates[ntype]:Clone()
	if gen == 1 then
		local gen = npc:WaitForChild("Gender")
		gen.Value = true
		local MaleGen = MnameGen[math.random(1, #MnameGen)]
		local FN = npc:WaitForChild("FirstName")
		FN.Value = MaleGen 
		local LastGen = LnameGen[math.random(1, #LnameGen)]
		local LN = npc:WaitForChild("LastName")
		LN.Value = LastGen
		local n2 = math.random(1,5)
		if n2 == 1 then
			MenShirt.Male1.Parent = npc
			MenPants.Male1P.Parent = npc
		elseif n2 == 2 then
			MenShirt.Male2.Parent = npc
			MenPants.Male2P.Parent = npc
		elseif n2 == 3 then
			MenShirt.Male3.Parent = npc
			MenPants.Male3P.Parent = npc
		elseif n2 == 4 then
			MenShirt.Male4.Parent = npc
			MenPants.Male4P.Parent = npc
		elseif n2 == 5 then
			MenShirt.Male5.Parent = npc
			MenPants.Male5P.Parent = npc
		end
		local n5 = math.random(1,5)
		if n5 == 1 then
		game:GetObjects("rbxassetid://16630147")[1].Parent = npc
		elseif n5 == 2 then
		game:GetObjects("rbxassetid://212967757")[1].Parent = npc
		elseif n5 == 3 then
		game:GetObjects("rbxassetid://835065199")[1].Parent = npc
		elseif n5 == 4 then
		game:GetObjects("rbxassetid://212961935")[1].Parent = npc
		elseif n5 == 5 then
		game:GetObjects("rbxassetid://12270248")[1].Parent = npc
		end

1 comment

0

Instead of using objects from the roblox library, just try and put the hairs in models within the ReplicatedStorage and give them a "middle" part that you will use to weld a random hair to the spawned NPC. Very similar to a morph for a war group that they step on, which takes the "middle" of the helmet for example, and welds that to the player's head.