spawn(function()while vars.Wandering.Value==false and human.Health>0 do vars.Chasing.Value=false vars.Wandering.Value=true local t,H=hroot.Position.x+math.random(-WanderX,WanderX),hroot.Position.z+math.random(-WanderZ,WanderZ)local function u(t)local H=3 if H>#t then H=3 end if t[H]==nil and H<#t then repeat H=H+1 wait()until t[H]~=nil return Vector3.new(1,0,0)+t[H]else H=3 return t[H]end end path=pfs:FindPathAsync(hroot.Position,Vector3.new(t,0,H))waypoint=path:GetWaypoints()local I local w=Vector3.FromNormalId(Enum.NormalId.Front)local i=hroot.CFrame*CFrame.new(w)w=i.p.unit local G=Ray.new(hroot.Position,w)local Z,k=game.Workspace:FindPartOnRay(G,hroot)if path and waypoint or u(waypoint)then if u(waypoint)~=nil and(u(waypoint)).Action==Enum.PathWaypointAction.Walk then human:MoveTo((u(waypoint)).Position)human.Jump=false end if u(waypoint)~=nil and(u(waypoint)).Action==Enum.PathWaypointAction.Jump then I=human.Changed:connect(function()human.Jump=true end)human:MoveTo(waypoint[4].Position)else human.Jump=false end if I then I:Disconnect()end else for t=3,#waypoint,1 do human:MoveTo(waypoint[t].Position)end end wait(math.random(4,6))vars.Wandering.Value=false end end)

spawn(function()
	while vars.Wandering.Value == false and human.Health > 0 do	
		vars.Chasing.Value = false	
		vars.Wandering.Value = true
		local desgx, desgz = hroot.Position.x+math.random(-WanderX,WanderX), hroot.Position.z+math.random(-WanderZ,WanderZ)
		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
		
		path = pfs:FindPathAsync(hroot.Position, Vector3.new(desgx, 0, desgz))
		waypoint = path:GetWaypoints()
		local connection;
		
		local direct = Vector3.FromNormalId(Enum.NormalId.Front)
		local ncf = hroot.CFrame * CFrame.new(direct)
		direct = ncf.p.unit
		local rootr = Ray.new(hroot.Position, direct)
		local phit, ppos = game.Workspace:FindPartOnRay(rootr, hroot)
		
		if path and waypoint or checkw(waypoint) then
			if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Walk then
				human:MoveTo( checkw(waypoint).Position )
				human.Jump = false
			end
			
			if checkw(waypoint) ~= nil and checkw(waypoint).Action == Enum.PathWaypointAction.Jump then
				connection = human.Changed:connect(function()
					human.Jump = true
				end)
				human:MoveTo( waypoint[4].Position )
			else
				human.Jump = false
			end
			
			if connection then
				connection:Disconnect()
			end
			
		else
			for i = 3, #waypoint do
				human:MoveTo( waypoint[i].Position )	
			end
		end
		wait(math.random(4,6))
		vars.Wandering.Value = false
	end
end)
