My movement script works like that:
go to part1.position if you arrived the position break the loop and go part2.position loop and do that for 18 times
So the issue is if npc catches the player in part4 while loop (or part10 it doesnt matter) Npc thinks or code "I need to go part4 because im in part4 while loop" but i dont want that, i want if npc catches the player while loops start over. (i hope i explained well)
Here is my npc movement code, i did that for 18 times i dont know if its a effect to performance
while wait(1.5) do
local distance = (NPC.HumanoidRootPart.Position - part1.Position).magnitude
if distance <= mag then
break
end
NPC.Humanoid:MoveTo(part1.Position)
end
Here is the event when npc catches the player
wait()
local dum = game.Workspace.CellatBaba
local players = game:GetService("Players")
local lead = game.Players:WaitForChild("leaderstats", 1)
local Remote = game.ReplicatedStorage.CheckPoint
local t = game.Workspace.SpawnBase.TeleportPad
game.Workspace.CellatBaba.Hitbox.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
Remote:FireServer()
game.Workspace.CellatBaba:SetPrimaryPartCFrame(CFrame.new(t.Position))
hit.Parent.Humanoid.Health = 0
end
end)

5 comments
sorry, what do you mean when you talk about part1, part2, part4 and part10?
They pointing where npc will go
If i want to move npc to part1 i can do "NPC.Humanoid:MoveTo(part1.Position)"
Do you mean that, when the player is caught, the npc returns to part1, or goes to part4, then continues on to part5?
yeah similiar to that, if player caught npc returns part1 and start over