Hello!
So I have a pathfinding script, but it lags!
What I mean:
If I move, it takes a few seconds before the npc starts going to my new position!
Why?
Script:
local function pathFind()
local target = getTarget()
if target then
local path = getPath(target)
if path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
humanoid:MoveTo(waypoint.Position)
local timeOut = humanoid.MoveToFinished:Wait(1)
if not timeOut then
humanoid:MoveTo(target.HumanoidRootPart.Position - (doge.HumanoidRootPart.CFrame.LookVector * 10))
end
end
else
humanoid:MoveTo(target.HumanoidRootPart.Position - (doge.HumanoidRootPart.CFrame.LookVector * 10))
end
end
end
while wait() do
pathFind()
end
No errors, thanks for any help!