I need help making a pathfinding script. I have some of it done and it wont work.
This is my script:
local pfs = game:GetService(“PathfindingService”)
local humanoid = script.Parent.Humanoid
local body = script.Parent:FindFirstChild(“Torso”)
local destination = game.Workspace:FindFirstChild(“Destination”).Position
local path = pfs:CreatePath()
path:ComputeAsync(body.Position, destination)
local waypoints = path:GetWaypoints()
for k, waypoint in pairs(waypoints) do
humanoid:MoveTo(waypoints.Position)
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
humanoid.MoveToFinished:Wait()
I’m guessing you are having issues with getting your NPC to jump. You didn’t actually say what your problem was since “it won’t work” doesn’t tell us what is going on. A better description would be “my NPC won’t move” or “my NPC gets stuck” or “my NPC moves, then stops”.
Is it an R6 or R15 NPC? You look for local body = script.Parent:FindFirstChild(“Torso”) but there is no Torso in an R15 rig.
Another thing would be to mention if you get any errors in your Output window.