Hey everyone I hope you are having a good day. Today I was working on my very basic pathfinding AI to try to fix an error. I finally fixed it but I got a new error “Unable to cast instance to vector3.” I had to tune my script to make sure it would not run until the torso of the humanoid was loaded in. I tried changing my variable “local destination = script.Parent:WaitForChild(“Torso”) or script.Parent.PrimaryPart” to
local destination = script.Parent:WaitForChild(“HumanoidRootPart”) or script.Parent.PrimaryPart
but I get an infinite yield error so I switched it back and I still get the vector3 error. The error happens on line 12 where the NPC computes a path.
My Script
local humanoid = script.Parent.Humanoid
local body = script.Parent:FindFirstChild("Torso") or script.Parent
local destination = script.Parent:WaitForChild("Torso") or script.Parent.PrimaryPart
--path maker
local path = pathfindingService:CreatePath()
--copute path
path:ComputeAsync(body.Position, destination)
-- get waypoints
local waypoints = path:GetWaypoints()
for k, waypoint in pairs(waypoints) do
humanoid:MoveTo(waypoints.Position)
if waypoints.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
humanoid.MoveToFinished:Wait()
end

