Attempt to index nil with 'GetChildren'

so i was writing this script that would give the npc a hair

Preformatted textlocal gender = math.random(2,2)
local hairs = {}
local facial = {}
local acc = {}
local haircolor = {}
local rs = game:GetService(“ReplicatedStorage”)
local ghairs = rs.Hairs.Female
local mhairs = rs.Hairs.Male

for _, v in ipairs(mhairs:GetChildren()) do
table.insert(haircolor, v)
end

local color = haircolor[math.random(#haircolor)]

function finditem(list, category)
for _, v in ipairs(list:GetChildren()) do
if v.Name == category then
print(v)
print(color)
return v
end
end
end

if gender == 1 then
print(“girl”)
elseif gender == 2 then
local isBald = math.random(1,5)
if isBald ~= 2 and isBald ~= 4 then
local hairfinder = finditem(mhairs, color)
print(mhairs)
print(color)
for _, v in ipairs(finditem(mhairs, color):GetChildren()) do
table.insert(hairs, v)
end
local chosenhair = hairs[math.random(#hairs)]
local hairgrab = hairfinder:FindFirstChild(chosenhair):Clone()
hairgrab.Parent = script.Parent
else
print(“bald”)
end
end`

but whenever i run it it gives me this error
Workspace.ZombieBase.Customize:34: attempt to index nil with ‘GetChildren’

i have a folder called Hairs in replicated storage which has two children Male and Female that each have several hair color folders within them with various hair assets.

Problem solved i just needed to put a if statement within the for loop instead of trying to have a variable act as a child.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.