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()