When npc catches the player npc movement code should be start over

Yup, you need to break the loop first
Change the repeating like this to break it:

Repeating = " "

One last question, when player caught npc will wait 30 seconds how can i do that? i tried to add wait(30)
but i didnt make it.

Easy first you need to break the loop then make the NPC move to his HumanoidRootPart position that will stop him then add 30 seconds delay after that he will back to part0
So your script should be like this:

local Part0 = game.Workspace.Part0
local Part1 = game.Workspace.Part1
local Part2 = game.Workspace.Part2
local Part3 = game.Workspace.Part3
local Part = Instance.new("Part")
local Repeating = "Part0"
local TouchFilter = false
local LeftTouch
local RightTouch
Part.Size = Vector3.new(16, 12, 16)
Part.Parent = script.Parent
Part.CanCollide = false
Part.Transparency = 1
Part.Massless = true
local weld = Instance.new("Weld")
weld.Parent = Part
weld.Part0 = Part
weld.Part1 = script.Parent.HumanoidRootPart
Part.Touched:Connect(function(hit)
	if hit.Name == "HumanoidRootPart" then
		if not TouchFilter then
			TouchFilter = true
			Repeating = " "
			 script.Parent.Humanoid:MoveTo(script.Parent.HumanoidRootPart.Position)
			wait(30)
			repeat
				script.Parent.Humanoid:MoveTo(Part0.Position)
				wait(0.1)
			until Repeating == "Part0"
			print(Repeating)
			LeftTouch:Disconnect()
			RightTouch:Disconnect()
			TouchFilter = false
		end
	end
end)
function touch(hit)
	wait(0.2)
	if hit == game.Workspace.Part0 then
		Repeating = "Part0"
		repeat
			script.Parent.Humanoid:MoveTo(Part1.Position)
			wait(0.1)
		until Repeating == "Part1" or Repeating == " "
	elseif hit == game.Workspace.Part1 then
		Repeating = "Part1"
		repeat
			script.Parent.Humanoid:MoveTo(Part2.Position)
			wait(0.1)
		until Repeating == "Part2" or Repeating == " "
	elseif hit == game.Workspace.Part2 then
		Repeating = "Part2"
		repeat
			script.Parent.Humanoid:MoveTo(Part3.Position)
			wait(0.1)
		until Repeating == "Part3" or Repeating == " "
	elseif hit == game.Workspace.Part3 then
		Repeating = "Part3"
		repeat
			script.Parent.Humanoid:MoveTo(Part0.Position)
			wait(0.1)
		until Repeating == "Part0" or Repeating == " "
	end
end

RightTouch = script.Parent.RightLowerLeg.Touched:Connect(touch)
LeftTouch = script.Parent.LeftLowerLeg.Touched:Connect(touch)
script.Parent.Humanoid:MoveTo(Part0.Position)

it didnt work, maybe because i have a teleport code

	if hit.Name == "HumanoidRootPart" then 
		NPC:SetPrimaryPartCFrame(CFrame.new(game.Workspace.Teleport.Position)) 
		if not TouchFilter then
			TouchFilter = true
			Repeating = " " 			
			 NPC.Humanoid:MoveTo(NPC.HumanoidRootPart.Position)
			wait(30)
			repeat
				NPC.Humanoid:MoveTo(part0.Position)
				wait(0.1)
			until Repeating == "Part0" 
			print(Repeating)

			TouchFilter = false
		end
	end
end)

Idk why it didn’t work for you, I put your teleport code in my script and it still work for me, after 30 second from teleporting NPC will back to the begin here is the place:

Baseplate.rbxl (51.6 KB)

try use:

NPC.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.Teleport.Position)

I dont know too man this is weird. Maybe if i set walkspeed 0 for 30 second it will okey

So the problem NPC dont back after 30 seconds? Still in teleport place?

yeah still teleporting but npc dont waiting for 30 second

maybe something firing moveto event

try do it like this:

if hit.Name == "HumanoidRootPart" then 
	if not TouchFilter then
		TouchFilter = true
		Repeating = " " 			
		NPC.Humanoid:MoveTo(NPC.HumanoidRootPart.Position)
        NPC.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.Teleport.Position)
		wait(30)
		repeat
			NPC.Humanoid:MoveTo(part0.Position)
			wait(0.1)
		until Repeating == "Part0" 
		TouchFilter = false
		end
	end
end)

No doesnt work, btw when npc first touched the player npc teleports but second touch nothings happen npc pass through the player.

But if i do like this:

if hit.Name == "HumanoidRootPart" then 
		NPC:SetPrimaryPartCFrame(CFrame.new(part0.Position))
		if not TouchFilter then
			TouchFilter = true
			Repeating = " " 			
			NPC.Humanoid:MoveTo(NPC.HumanoidRootPart.Position)
			NPC.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.Teleport.Position)
			wait(30)
			repeat
				NPC.Humanoid:MoveTo(part0.Position)
				wait(0.1)
			until Repeating == "Part0" 
			TouchFilter = false
		end
	end

Teleports the npc every time npc touched.

Yes because NPC need to go back to the begin, the the touch filter will open

do you use this script from the client?

I use local script, because npc is a client sided

Btw i have a idea but its kinda dumb. Im gonna add 3 wall around start (start is where npc teleporting and where npc begin to walk) if player touch the npc i will enable walls cancollide for 30 seconds so npc cant get out when 30 second is over i will cancollide off again

What do you think about that idea ?

Its really working dude xd is it okey to do like that ?

So you will do something like this maybe?

Baseplate.rbxl (51.9 KB)

yeah yeah i did something like that