Helloo!
I’m just starting out with scripting and I was practicing some pathfinding. I had no errors in the script itself, I anchored all parts except for the NPC and somehow this happened:
How can I fix this?
Script:
-- get pathfinding service
local pathfindingService = game:GetService("PathfindingService")
-- Variables for NPC humanoid, torso, and destination
local humanoid = script.Parent.Humanoid
local body = script.Parent:FindFirstChild("HumanoidRootPart") or script.Parent:FindFirstChild("Torso")
local destination = game.Workspace.Destination.Position
-- create path object
local path = pathfindingService:CreatePath()
-- compute a path
path:ComputeAsync(body.Position, destination)
-- get the waypoints table
local waypoints = path:GetWaypoints()
-- iterate through all waypoints, and jump when necessary
for k, waypoint in pairs(waypoints) do
humanoid:MoveTo(waypoint.Position)
-- change humanoid state to jump if necessary
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
humanoid.MoveToFinished:Wait()
end