function AI()if Mode==0 then wait(math.random(5,15)/10)followPath(hroot.Position+Vector3.new(math.random(-MaxInc,MaxInc),0,math.random(-MaxInc,MaxInc)))elseif Mode==1 then target=findNearestTorso(hroot.Position)if target~=nil then if CanSee==true and(hroot.Position-target.Position).Magnitude<=MinDistance then waypoint=nil else path:ComputeAsync(hroot.Position,target.Position)waypoint=path:GetWaypoints()local a local function R(a)local R=3 if R>#a then R=3 end if a[R]==nil and R<#a then repeat R=R+1 wait()until a[R]~=nil return Vector3.new(1,0,0)+a[R]else R=3 return a[R]end end if path.Status==Enum.PathStatus.Success then human.WalkToPart=nil if waypoint or R(waypoint)then if R(waypoint)~=nil and(R(waypoint)).Action==Enum.PathWaypointAction.Walk then human:MoveTo((R(waypoint)).Position)end if a then a:Disconnect()end else for a=3,#waypoint,1 do human:MoveTo(waypoint[a].Position)end end else wait(math.random(5,15)/10)followPath(hroot.Position+Vector3.new(math.random(-MaxInc,MaxInc),0,math.random(-MaxInc,MaxInc)))end end end elseif Mode==2 then target=findNearestTorso(hroot.Position)if target~=nil then if CanSee==true and(hroot.Position-target.Position).Magnitude<=MinDistance then waypoint={}waypoint=nil else path:ComputeAsync(hroot.Position,target.Position)waypoint=path:GetWaypoints()local a local function R(a)local R=3 if R>#a then R=3 end if a[R]==nil and R<#a then repeat R=R+1 wait()until a[R]~=nil return Vector3.new(1,0,0)+a[R]else R=3 return a[R]end end if path.Status==Enum.PathStatus.Success and Memory>0 then human.WalkToPart=nil if waypoint or R(waypoint)then if R(waypoint)~=nil and(R(waypoint)).Action==Enum.PathWaypointAction.Walk then human:MoveTo((R(waypoint)).Position)end if a then a:Disconnect()end else for a=3,#waypoint,1 do human:MoveTo(waypoint[a].Position)end end else waypoint=nil wait(math.random(5,15)/10)followPath(hroot.Position+Vector3.new(math.random(-MaxInc,MaxInc),0,math.random(-MaxInc,MaxInc)))end end end elseif Mode==3 then end end
--followPath(destination)
-------------------------------------------------------------------
-------------------------------------------------------------------
-------------------------------------------------------------------

function AI()
	if Mode == 0 then
		--waypoint = nil
		--print("Patrol mode")
		wait(math.random(5, 15) / 10)
		followPath(hroot.Position + Vector3.new(math.random(-MaxInc, MaxInc), 0, math.random(-MaxInc, MaxInc)))

		--human:MoveTo(zombie.Torso.Position + Vector3.new(math.random(-MaxInc, MaxInc), 0, math.random(-MaxInc, MaxInc)), CurrentPart)
	elseif Mode == 1 then
		target = findNearestTorso(hroot.Position)

		if target ~= nil then
			if CanSee == true and (hroot.Position - target.Position).Magnitude <= MinDistance then
				waypoint = nil
			else
				path:ComputeAsync(hroot.Position, target.Position)
				waypoint = path:GetWaypoints()

				local connection
				local function checkw(t)
					local ci = 3
					if ci > #t then
						ci = 3
					end
					if t[ci] == nil and ci < #t then
						repeat
							ci = ci + 1
							wait()
						until t[ci] ~= nil
						return Vector3.new(1, 0, 0) + t[ci]
					else
						ci = 3
						return t[ci]
					end
				end
				if path.Status == Enum.PathStatus.Success then
					--print("Chasing "..target.Parent.Name)
					human.WalkToPart = nil
					if waypoint or checkw(waypoint) then
						if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Walk then
							human:MoveTo(checkw(waypoint).Position)
						end

						if connection then
							connection:Disconnect()
						end
					else
						for i = 3, #waypoint do
							human:MoveTo(waypoint[i].Position)
						end
					end
				else
					--print("No Path,Patrolling")
					wait(math.random(5, 15) / 10)
					followPath(
						hroot.Position + Vector3.new(math.random(-MaxInc, MaxInc), 0, math.random(-MaxInc, MaxInc))
					)
				end
			end
		end
	elseif Mode == 2 then
		target = findNearestTorso(hroot.Position)

		if target ~= nil then
			if CanSee == true and (hroot.Position - target.Position).Magnitude <= MinDistance then
				waypoint = {}
				waypoint = nil
			else
				path:ComputeAsync(hroot.Position, target.Position)
				waypoint = path:GetWaypoints()

				local connection
				local function checkw(t)
					local ci = 3
					if ci > #t then
						ci = 3
					end
					if t[ci] == nil and ci < #t then
						repeat
							ci = ci + 1
							wait()
						until t[ci] ~= nil
						return Vector3.new(1, 0, 0) + t[ci]
					else
						ci = 3
						return t[ci]
					end
				end
				if path.Status == Enum.PathStatus.Success and Memory > 0 then
					--print("Chasing "..target.Parent.Name)
					human.WalkToPart = nil
					if waypoint or checkw(waypoint) then
						if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Walk then
							human:MoveTo(checkw(waypoint).Position)
						end

						if connection then
							connection:Disconnect()
						end
					else
						for i = 3, #waypoint do
							human:MoveTo(waypoint[i].Position)
						end
					end
				else
					waypoint = nil
					--print("No Path,Patrolling")
					wait(math.random(5, 15) / 10)
					followPath(
						hroot.Position + Vector3.new(math.random(-MaxInc, MaxInc), 0, math.random(-MaxInc, MaxInc))
					)
				end
			end
		end
	elseif Mode == 3 then
		--	print("Guarding")
	end
end
