PathfindingModule.Move(npc, workspace.Part.Position)
print("passed")
---MODULE
PathfindingModule.Move = function(npc, pos)
local walkAnim = npc.Humanoid:LoadAnimation(npc.Animate.walk.WalkAnim)
local idleAnim = npc.Humanoid:LoadAnimation(npc.Animate.idle.Animation1)
local path = PathfindingService:CreatePath()
local connecting
path:ComputeAsync(npc.HumanoidRootPart.Position, pos)
for _, waypoint in pairs(path:GetWaypoints()) do
local part = Instance.new("Part")
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Transparency = 1
part.Position = waypoint.Position
part.Anchored = true
part.CanCollide = false
part.Parent = game.Workspace
npc.Humanoid:MoveTo(waypoint.Position)
npc.Humanoid.MoveToFinished:Wait()
connecting = npc.Humanoid.MoveToFinished:Connect(function(reached)
wait(3)
connecting:Disconnect()
end)
npc.Humanoid.Running:Connect(function(speed)
if speed < 1 then
walkAnim:Stop()
idleAnim:Play()
else
if speed > 4 then
idleAnim:Stop()
walkAnim:Play()
end
end
end)
end
end
The top line of code makes it so it waits until the npc reaches part.position then it executes code after that line,
So for example “passed” wouldn’t print right now until NPC reaches destination. I don’t want that
(I can’t remove npc.Humanoid.MoveToFinished:Wait() line since it breaks npcs, they stop before reaching their destination, don’t know why)