I’m trying to make a system so that when I move a part the NPC pathfinds to it.
It goes to the original position instead of going to the new position
local PathFindingService = game:GetService("PathfindingService")
local human = script.Parent:WaitForChild("Humanoid")
local torse = script.Parent:WaitForChild("Torso")
local modifierVolume = game.Workspace.crosswalk
local modifier = Instance.new("PathfindingModifier", modifierVolume)
modifier.Label = "All"
local agentParameters = {
Costs = {
All = math.random(1,100) = 1 and 100 or 1
}
}
local path = PathFindingService:CreatePath(agentParameters)
path:ComputeAsync(torse.Position, game.Workspace.End.Position)
local waypoints = path:GetWaypoints()
path.Blocked:Connect(function()
print("Path Blocked")
end)
wait(0.1)
for i, waypoint in pairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
human:ChangeState(Enum.HumanoidStateType.Jumping)
end
human:MoveTo(waypoint.Position)
human.MoveToFinished:Wait(1)
end
human:MoveTo(game.Workspace.End.Position)
wait()
script.Parent:Destroy()
How do I make it so it updates the path every time the End part is moved?