I connect the character’s accessories to the Black List and if the new object has a Humanoid, I will use the For statement to find the accessories and put them in the Black List. However, FindFirstChild (“Humanoid”) cannot find the humanoid and continues to return nil.(The character has a Humanoid and has tried looping FindFirstChild (“Humanoid”) with a While statement, but all return nil.) And the Connect function is in another module script and the code for finding the accessories is in another module.
ConnectDetectFunction = function(Obj) --- This function is Connected with game.Workspace.ChildAddd()
local list = {}
print(Obj:GetFullName())
local human = Obj:FindFirstChild("Humanoid")
print(human)
if Obj:IsA("Model") and human then
for i,v in pairs(Obj:GetChildren()) do
if v:IsA("Accessory") or v:IsA("Tool") or v:IsA("Model") or v:IsA("Hat") then
table.insert(list,v)
end
end
end
return list
end;
game.Workspace.ChildAdded:Connect(function(v)
local StartDetect = self.ConnectDetectFunction(v)
for n,ins in pairs(StartDetect) do
if ins then
table.insert(self.BlackList,ins)
end
end
end)
local function ConnectDetectFunction(Obj) --- This function is Connected with game.Workspace.ChildAddd()
local list = {}
print(Obj:GetFullName())
local human = Obj:FindFirstChild("Humanoid")
print(human)
if Obj:IsA("Model") and human then
for i,v in pairs(Obj:GetChildren()) do
if v:IsA("Accessory") or v:IsA("Tool") or v:IsA("Model") or v:IsA("Hat") then
table.insert(list,v)
end
end
end
return list
end;
game.Workspace.ChildAdded:Connect(function(v)
local StartDetect = ConnectDetectFunction(v)
for n,ins in pairs(StartDetect) do
if ins then
table.insert(self.BlackList,ins)
end
end
end)
My apologies, I didn’t realize it was a module script. Actually I think I see what is happening, ignore my first reply.
I think it is trying to print the humanoid before the humanoid is added to the character. Because it adds the character, and your script prints human, and then it adds the humanoid after. Maybe try this instead:
local Players = game:GetService("Players")
ConnectDetectFunction = function(Obj) --- This function is Connected with game.Workspace.ChildAddd()
local list = {}
print(Obj:GetFullName())
if Players:GetPlayerFromCharacter(Obj) then
repeat wait() until Obj:FindFirstChild("Humanoid")
end
local human = Obj:FindFirstChild("Humanoid")
print(human)
if Obj:IsA("Model") and human then
for i,v in pairs(Obj:GetChildren()) do
if v:IsA("Accessory") or v:IsA("Tool") or v:IsA("Model") or v:IsA("Hat") then
table.insert(list,v)
end
end
end
return list
end;