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 v local function C(v)local C=3 if C>#v then C=3 end if v[C]==nil and C<#v then repeat C=C+1 wait()until v[C]~=nil return Vector3.new(1,0,0)+v[C]else C=3 return v[C]end end if path.Status==Enum.PathStatus.Success then human.WalkToPart=nil if waypoint or C(waypoint)then if C(waypoint)~=nil and(C(waypoint)).Action==Enum.PathWaypointAction.Walk then human:MoveTo((C(waypoint)).Position)end if v then v:Disconnect()end else for v=3,#waypoint,1 do human:MoveTo(waypoint[v].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 v local function C(v)local C=3 if C>#v then C=3 end if v[C]==nil and C<#v then repeat C=C+1 wait()until v[C]~=nil return Vector3.new(1,0,0)+v[C]else C=3 return v[C]end end if path.Status==Enum.PathStatus.Success and Memory>0 then human.WalkToPart=nil if waypoint or C(waypoint)then if C(waypoint)~=nil and(C(waypoint)).Action==Enum.PathWaypointAction.Walk then human:MoveTo((C(waypoint)).Position)end if v then v:Disconnect()end else for v=3,#waypoint,1 do human:MoveTo(waypoint[v].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



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