spawn(function()while vars.Wandering.Value==false and human.Health>0 do vars.Chasing.Value=false vars.Wandering.Value=true local V,c=hroot.Position.x+math.random(-WanderX,WanderX),hroot.Position.z+math.random(-WanderZ,WanderZ)local function t(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 path=pfs:FindPathAsync(hroot.Position,Vector3.new(V,0,c))waypoint=path:GetWaypoints()local s local h=Vector3.FromNormalId(Enum.NormalId.Front)local p=hroot.CFrame*CFrame.new(h)h=p.p.unit local U=Ray.new(hroot.Position,h)local C,r=game.Workspace:FindPartOnRay(U,hroot)if path and waypoint or t(waypoint)then if t(waypoint)~=nil and(t(waypoint)).Action==Enum.PathWaypointAction.Walk then human:MoveTo((t(waypoint)).Position)human.Jump=false end if t(waypoint)~=nil and(t(waypoint)).Action==Enum.PathWaypointAction.Jump then s=human.Changed:connect(function()human.Jump=true end)human:MoveTo(waypoint[4].Position)else human.Jump=false end if s then s:Disconnect()end else for V=3,#waypoint,1 do human:MoveTo(waypoint[V].Position)end end wait(math.random(4,6))vars.Wandering.Value=false end end)
-- wandering
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)
