Pathfinding Error with HumanoidRootPart not found?

I have a npc which goes and pathfinds directions to random points. The thing is, I keep getting an error that “HumanoidRootPart is not a valid member of Model.” Even though it clearly is. I do not know why this problem is occuring, but I have paused it in the middle of the game and checked and saw that HumanoidRootPart is inside the npc and I used print scripts. Strangely with the print scripts, randomly, it says that the HumaniodRootPart is there, while other times it does. Here is my script:

repeat wait() until script.Parent.Parent.Parent == game.Workspace

local PathfindingService = game:GetService(“PathfindingService”)
function move()
local zombie = script.Parent
local humanoid = zombie.Humanoid
local destination = game.Workspace.NPCPaths:FindFirstChild(math.random(1, 28))

– Create the path object
local path = PathfindingService:CreatePath()

– Compute the path
path:ComputeAsync(zombie.HumanoidRootPart.Position, destination.Position)–error happens here

– Get the path waypoints
local waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
local part = Instance.new(“Part”)
part.Shape = “Ball”
part.Material = “Neon”
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = waypoint.Position
part.Anchored = true
part.CanCollide = false
part.Parent = game.Workspace

-- Move zombie to the next waypoint
humanoid:MoveTo(waypoint.Position)
-- Wait until zombie has reached the waypoint before continuing
humanoid.MoveToFinished:Wait()

end
move()
end
move()

1 Like

Try using WaitForChild() to yield until the HumanoidRootPart is found.

local root = zombie:WaitForChild("HumanoidRootPart")

path:ComputeAsync(root.Position, destination.Position)

I get infinite yield. :confused:

Does your game utilize R15 or R6 characters? And if it’s both then which one are you testing on?

It only uses r6. I tried r15 but couldn’t get animations for it.

Then that’s the issue. I highly doubt that HumanoidRootPart is in R6, instead use Torso

It says Torso is not a valid member of model.

HumanoidRootPart (the invisible torso-like block) is in R6, it’s necessary for humanoid movement.

I’ve also tried running the code @CaptainD_veloper posted in the OP into a sample humanoid model and it does indeed run (after a few minor edits). Make sure that the HumanoidRootPart is in the first parent model in the hierarchy, like Zombie > HumanoidRootPart and that the script is in Zombie.

1 Like

I have multiple zombies being controlled.

That’s fine, but with the way your script is currently setup it should look like something similar to the image explorer above. The number of zombies aren’t a factor in this.

Oh, still it prints it and im not sure why it does it.