Fairly simple stuff, when the character is added, a server script runs and prints all the children of the character, excluding the HumanoidRootPart and the Humanoid via an if statement.
local function CharAdded(Character)
for _, v in pairs(Character:GetChildren()) do
if v:IsA("Part") or v:IsA("BasePart") or v:IsA("MeshPart") or v.Name ~= "HumanoidRootPart" then
local part = v
print(part)
end
end
end
BUT WHY IS IT STILL PRINTING THE HUMANOID
And no, I don’t want a band-aid fix like specifically excluding the humanoid in the if statement, I want an explanation as to why the humanoid isn’t being filtered out by the if statement.
Make it check if it’s a Humanoid to avoid this then.
I want to say Humanoid is considered a BasePart, and that is what is causing it.
local function CharAdded(Character)
for _, v in pairs(Character:GetChildren()) do
if v.Name ~= 'Humanoid' and (v:IsA("Part") or v:IsA("BasePart") or v:IsA("MeshPart") or v.Name ~= "HumanoidRootPart") then
local part = v
print(part)
end
end
end
local function CharAdded(Character)
for _, v in pairs(Character:GetChildren()) do
if (v:IsA("Part") or v:IsA("BasePart") or v:IsA("MeshPart")) and v.Name ~= "HumanoidRootPart" then
local part = v
print(part)
end
end
end
The Humanoid is not a BasePart since this does not inherit properties from the class. The real reason is because each condition is chained or operators. The way it works is it goes through every condition and if it is true, will yield true as the result, else it returns the next one. The condition checks for if it is a base part or similar does fail, but the one check it passes is the name check to ensure it is not named “HumanoidRootPart”.
Your desired result is to have an instance that is both a base part “and” is not named “HumanoidRootPart”, right? In this case, you need the and operator:
if (v:IsA("BasePart") and v.Name ~= "HumanoidRootPart") then
-- do stuff
end
P.S: Parts and mesh parts are base parts since the first two inherit members from the BasePart class