i was coding a script where a dummy chases after a part, it was working fine yesterday but now it broke somehow, now it just moves directly to the part instead of pathfinding to it
pathfinding script:
local target = workspace:WaitForChild("target")
local pathfindingservice = game:GetService("PathfindingService")
local root = script.Parent:WaitForChild("HumanoidRootPart")
local humanoid = script.Parent:WaitForChild("Humanoid")
local path
local waypoints
local waypointnumber = 1
local updatepath = coroutine.create(function()
while true do
wait(1)
if path ~= nil then
path:Destroy()
end
path = pathfindingservice:CreatePath()
path:ComputeAsync(root.Position, target.Position)
if path.Status == Enum.PathStatus.Success then
waypoints = path:GetWaypoints()
waypointnumber = 1
else
print("error.")
end
end
end)
coroutine.resume(updatepath)
repeat wait() until waypoints ~= nil
while true do
if waypointnumber <= #waypoints then
local waypoint = waypoints[waypointnumber]
if waypoint.Action == Enum.PathWaypointAction.Jump then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
else
humanoid:MoveTo(waypoint.Position)
end
waypointnumber = waypointnumber + 1
humanoid.MoveToFinished:Connect(wait)
else
wait()
end
end