Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to stop npc from following path midway?

Asked by 2 years ago

So I have a script, and I copied the pathfind script that follows it's enemy. And if it sees it's enemy it's gonna stop itself from walking to the target.

Well, that's what I want it to do, but it doesn't work.

Script (not full script):

01local ray1 = Ray.new(script.Parent.M16.Shoot.Position, (v.HumanoidRootPart.Position - script.Parent.M16.Shoot.Position).Unit * 1000)
02            local hit1, position1 = workspace:FindPartOnRayWithIgnoreList(ray1, {script.Parent})
03            if not hit1:IsDescendantOf(v) then
04                local Destination = v.HumanoidRootPart.Position
05                local Path = PathfindingService:CreatePath()
06                local NPC = script.Parent
07                local Humanoid = NPC.Humanoid
08                Path:ComputeAsync(NPC.PrimaryPart.Position, Destination)
09 
10                local activeCoroutine = nil
11                local follow=true
12 
13                -- Loop update
14                coroutine.wrap(function()
15                    while (follow) do
View all 50 lines...

Please help

Answer this question