I am using pathfinding service to move an NPC to a part, but I need to pause the movement if a value is true. For example, if the value is true the NPC will stop then when the value is false it will continue to move on its path. I’ve been looking around for a few days, but I can’t find an answer.
The pathfinding script I’m using (Server)
local RUN = game:GetService("RunService")
local PS = game:GetService("PathfindingService")
local Path = PS:CreatePath({
AgentRadius = 3.5,
AgentHeight = 5,
AgentCanJump = false,
AgentCanClimb = false,
WaypointSpacing = 4,
Costs = nil
})
task.wait(5)
Path:ComputeAsync(script.Parent.HumanoidRootPart.Position, game.Workspace.test.Position)
for _, waypoint in pairs(Path:GetWaypoints()) do
script.Parent.Humanoid:MoveTo(script.Parent.waypoint.Position)
script.Parent.Humanoid.MoveToFinished:Wait()
end
local RUN = game:GetService("RunService")
local PS = game:GetService("PathfindingService")
local Path = PS:CreatePath({
AgentRadius = 3.5,
AgentHeight = 5,
AgentCanJump = false,
AgentCanClimb = false,
WaypointSpacing = 4,
Costs = nil
})
task.wait(5)
CantRun = false
Path:ComputeAsync(script.Parent.HumanoidRootPart.Position, game.Workspace.test.Position)
for _, waypoint in pairs(Path:GetWaypoints()) do
if CantRun == false then
script.Parent.Humanoid:MoveTo(script.Parent.waypoint.Position)
script.Parent.Humanoid.MoveToFinished:Wait()
end
end
I think that would work. You can just update can run with a value or whatever you want
Maybe put it in a while loop then add in like a 1 second wait so:
while true do
for _, waypoint in pairs(Path:GetWaypoints()) do
if CantRun == false then
script.Parent.Humanoid:MoveTo(script.Parent.waypoint.Position)
script.Parent.Humanoid.MoveToFinished:Wait()
end
task.wait(1)
end
end