dist=20 function followany()following=true while following==true do local D=game.Players:children()for V=1,#D,1 do local x=game.Workspace:findFirstChild(D[V].Name)if x~=nil then local D=x.Torso local V=x.Torso.Position local k=script.Parent.Torso.Position local u=math.sqrt(((V.x-k.x)^2+(V.y-k.y)^2)+(V.z-k.z)^2)if smallest==nil then smallest=u target=D elseif u<smallest then smallest=u target=D end end end if smallest==nil then stopmoving()return end if smallest>6*dist then return end script.Parent.Humanoid:MoveTo(target.Position,target)wait(.5)for D=1,6,1 do if target.Parent.Humanoid.Health<1 then stopmoving()else wait(.5)end end end end function gohome()script.Parent.Humanoid:MoveTo(Vector3.new(0,0,0),game.Workspace.Bases.Base)end function stopmoving()script.Parent.Humanoid:MoveTo(script.Parent.Torso.Position,script.Parent.Torso)end function follow(D)following=true local V=game.Workspace:findFirstChild(D)if V==nil then return end while following==true do script.Parent.Humanoid:MoveTo(V.Torso.Position,V.Torso)wait(.5)for D=1,3,1 do if V.Humanoid.Health<1 then following=false stopmoving()return end wait(.5)end end end function attack(D)if script.Parent:findFirstChild("\083\119\111\114\100")~=nil then following=true local V=game.Workspace:findFirstChild(D)if V==nil then return end while following==true do script.Parent.Humanoid:MoveTo(V.Torso.Position,V.Torso)wait(.5)for D=1,3,1 do if V.Humanoid.Health<1 then following=false stopmoving()return end local x=V.Torso.Position local k=script.Parent.Torso.Position local u=math.sqrt(((x.x-k.x)^2+(x.y-k.y)^2)+(x.z-k.z)^2)if u<10 then script.Parent.Humanoid:MoveTo(V.Torso.Position,V.Torso)slash()if k.y-x.y>3 and k.y-x.y<7 then script.Parent.Humanoid:MoveTo(V.Torso.Position+Vector3.new(math.random(-4,4),0,math.random(-4,4)),V.Torso)end end wait(1)end end end end function attackany()if script.Parent:findFirstChild("\083\119\111\114\100")~=nil then following=true while following==true do local D=game.Players:children()for V=1,#D,1 do local x=game.Workspace:findFirstChild(D[V].Name)if x~=nil then local D=x.Torso local V=x.Torso.Position local k=script.Parent.Torso.Position local u=math.sqrt(((V.x-k.x)^2+(V.y-k.y)^2)+(V.z-k.z)^2)if smallest==nil then smallest=u target=D elseif u<smallest then smallest=u target=D end end end if smallest==nil then stopmoving()return end if smallest>6*dist then return end script.Parent.Humanoid:MoveTo(target.Position,target)if smallest<10 then slash()end if target.Parent==nil then stopmoving()return end wait(.5)for D=1,3,1 do if target.Parent.Humanoid.Health<1 then stopmoving()else local D=target.Position local V=script.Parent.Torso.Position local x=math.sqrt(((D.x-V.x)^2+(D.y-V.y)^2)+(D.z-V.z)^2)if x<10 then script.Parent.Humanoid:MoveTo(target.Position,target)slash()if V.y-D.y>3 and V.y-D.y<7 then script.Parent.Humanoid:MoveTo(D.Torso.Position+Vector3.new(math.random(-4,4),0,math.random(-4,4)),D.Torso)end end wait(1)end end end end end function patrol()if points==nil then points=0 if game.Workspace:findFirstChild("\112\112\049")~=nil then pp1=game.Workspace:findFirstChild("\112\112\049")local D=points+1 if game.Workspace:findFirstChild("\112\112\050")~=nil then pp2=game.Workspace:findFirstChild("\112\112\050")local V=D+1 if game.Workspace:findFirstChild("\112\112\051")~=nil then pp3=game.Workspace:findFirstChild("\112\112\051")local D=V+1 if game.Workspace:findFirstChild("\112\112\052")~=nil then pp4=game.Workspace:findFirstChild("\112\112\052")local V=D+1 if game.Workspace:findFirstChild("\112\112\053")~=nil then pp5=game.Workspace:findFirstChild("\112\112\053")local D=V+1 if game.Workspace:findFirstChild("\112\112\054")~=nil then pp6=game.Workspace:findFirstChild("\112\112\054")local V=D+1 if game.Workspace:findFirstChild("\112\112\055")~=nil then pp7=game.Workspace:findFirstChild("\112\112\055")local D=V+1 if game.Workspace:findFirstChild("\112\112\056")~=nil then pp8=game.Workspace:findFirstChild("\112\112\056")local V=D+1 if game.Workspace:findFirstChild("\112\112\057")~=nil then pp9=game.Workspace:findFirstChild("\112\112\057")local D=V+1 end end end end end end end end end end if points<1 then return end patrolling=true local D=2 if points==1 then return end if points>1 then while patrolling==true do script.Parent.Humanoid:MoveTo(pp1.Position,pp1)wait(D)script.Parent.Humanoid:MoveTo(pp2.Position,pp2)wait(D)if points>2 then script.Parent.Humanoid:MoveTo(pp3.Position,pp3)wait(D)if points>3 then script.Parent.Humanoid:MoveTo(pp4.Position,pp4)wait(D)if points>4 then script.Parent.Humanoid:MoveTo(pp5.Position,pp5)wait(D)if points>5 then script.Parent.Humanoid:MoveTo(pp6.Position,pp6)wait(D)if points>6 then script.Parent.Humanoid:MoveTo(pp7.Position,pp7)wait(D)if points>7 then script.Parent.Humanoid:MoveTo(pp8.Position,pp8)wait(D)if points>8 then script.Parent.Humanoid:MoveTo(pp9.Position,pp9)wait(D)end end end end end end end end end end function goto(D,V)while true do end end function slash()for D=1,3,1 do wait(.3)RightShoulder.MaxVelocity=2 LeftShoulder.MaxVelocity=1 RightShoulder.DesiredAngle=-2.14 LeftShoulder.DesiredAngle=0 RightHip.DesiredAngle=0 LeftHip.DesiredAngle=0 wait(.2)RightShoulder.MaxVelocity=2 LeftShoulder.MaxVelocity=1 RightShoulder.DesiredAngle=0 LeftShoulder.DesiredAngle=0 RightHip.DesiredAngle=0 LeftHip.DesiredAngle=0 end end function defence()proxkill=true while proxkill==true do local D=game.Players:children()for V=1,#D,1 do local x=game.Workspace:findFirstChild(D[V].Name)if x~=nil then local D=x.Torso.Position local V=script.Parent.Torso.Position local k=math.sqrt(((D.x-V.x)^2+(D.y-V.y)^2)+(D.z-V.z)^2)if k<dist and k>8 then local V=Instance.new("\069\120\112\108\111\115\105\111\110")V.Position=D V.Parent=game.Workspace end end end wait(1)end end

dist=20

function followany()
following=true
	while following==true do

		local ch=game.Players:children()
		for i=1, #ch do
			local l=game.Workspace:findFirstChild(ch[i].Name)
			if l~=nil then
				local s=l.Torso
				local p=l.Torso.Position
				local q=script.Parent.Torso.Position
				local d=math.sqrt( ((p.x-q.x)^2)+((p.y-q.y)^2)+((p.z-q.z)^2) )
				if smallest==nil then
					smallest=d
					target=s
				elseif d<smallest then
					smallest=d
					target=s
				end
			end
		end

		if smallest==nil then stopmoving() return end
		
		if smallest>6*dist then return end
		
		script.Parent.Humanoid:MoveTo(target.Position, target)

		wait(0.5)
		for i=1, 6 do
			if target.Parent.Humanoid.Health<1 then stopmoving() else	wait(0.5) end
		end
	end
end



function gohome()
	script.Parent.Humanoid:MoveTo(Vector3.new(0,0,0), game.Workspace.Bases.Base)
end
function stopmoving()
	script.Parent.Humanoid:MoveTo(script.Parent.Torso.Position, script.Parent.Torso)
end

function follow(name)
	following=true

	local p=game.Workspace:findFirstChild(name)
	if p==nil then return end
	while following==true do	
		script.Parent.Humanoid:MoveTo(p.Torso.Position, p.Torso)
		wait(0.5)
		for i=1, 3 do
			if p.Humanoid.Health<1 then following=false; stopmoving() return end
			wait(0.5)
		end
	end
end

function attack(name)
	if script.Parent:findFirstChild("Sword")~=nil then	
		following=true
		local p=game.Workspace:findFirstChild(name)
		if p==nil then return end
		while following==true do
			script.Parent.Humanoid:MoveTo(p.Torso.Position, p.Torso)
			wait(0.5)
			for i=1, 3 do
				if p.Humanoid.Health<1 then following=false; stopmoving() return end
				local l=p.Torso.Position
				local q=script.Parent.Torso.Position
				local d=math.sqrt( ((l.x-q.x)^2)+((l.y-q.y)^2)+((l.z-q.z)^2) )
				if d<10 then
					script.Parent.Humanoid:MoveTo(p.Torso.Position, p.Torso); slash()
					if (q.y-l.y)>3 and (q.y-l.y)<7 then
						script.Parent.Humanoid:MoveTo(p.Torso.Position+Vector3.new(math.random(-4,4),0,math.random(-4,4)), p.Torso);
					end
				end
				wait(1)
			end
		end
	end
end

function attackany()
if script.Parent:findFirstChild("Sword")~=nil then	

	following=true
		while following==true do

			local ch=game.Players:children()
			for i=1, #ch do
				local l=game.Workspace:findFirstChild(ch[i].Name)
				if l~=nil then
					local s=l.Torso
					local p=l.Torso.Position
					local q=script.Parent.Torso.Position
					local d=math.sqrt( ((p.x-q.x)^2)+((p.y-q.y)^2)+((p.z-q.z)^2) )
					if smallest==nil then
						smallest=d
						target=s
					elseif d<smallest then
						smallest=d
						target=s
					end
				end
			end

			if smallest==nil then stopmoving() return end
			
			if smallest>6*dist then return end
			
			script.Parent.Humanoid:MoveTo(target.Position, target)

			if smallest<10 then
				slash()
			end
			if target.Parent==nil then stopmoving() return end
			wait(0.5)
			for i=1, 3 do
				if target.Parent.Humanoid.Health<1 then 
					stopmoving() 
				else
					local p=target.Position
					local q=script.Parent.Torso.Position
					local d=math.sqrt( ((p.x-q.x)^2)+((p.y-q.y)^2)+((p.z-q.z)^2) )
					if d<10 then
						script.Parent.Humanoid:MoveTo(target.Position, target); slash()
						if (q.y-p.y)>3 and (q.y-p.y)<7 then
							script.Parent.Humanoid:MoveTo(p.Torso.Position+Vector3.new(math.random(-4,4),0,math.random(-4,4)), p.Torso);
						end
					end
					wait(1)
				end
			end
		end
	end
end


function patrol()
	if points==nil then
		points=0
		if game.Workspace:findFirstChild("pp1")~=nil then
		pp1=game.Workspace:findFirstChild("pp1")
		local points=points+1
			if game.Workspace:findFirstChild("pp2")~=nil then
			pp2=game.Workspace:findFirstChild("pp2")
		local points=points+1
				if game.Workspace:findFirstChild("pp3")~=nil then
				pp3=game.Workspace:findFirstChild("pp3")
		local points=points+1
					if game.Workspace:findFirstChild("pp4")~=nil then
					pp4=game.Workspace:findFirstChild("pp4")
		local points=points+1
						if game.Workspace:findFirstChild("pp5")~=nil then
						pp5=game.Workspace:findFirstChild("pp5")
		local points=points+1
							if game.Workspace:findFirstChild("pp6")~=nil then
							pp6=game.Workspace:findFirstChild("pp6")
		local points=points+1
								if game.Workspace:findFirstChild("pp7")~=nil then
								pp7=game.Workspace:findFirstChild("pp7")
		local points=points+1
									if game.Workspace:findFirstChild("pp8")~=nil then
									pp8=game.Workspace:findFirstChild("pp8")
		local points=points+1
										if game.Workspace:findFirstChild("pp9")~=nil then
										pp9=game.Workspace:findFirstChild("pp9")
		local points=points+1
										end
									end
								end
							end
						end
					end
				end
			end
		end
	end

	if points<1 then return end
	patrolling=true
	local time=2
	if points==1 then return end
	if points>1 then
		while patrolling==true do
			script.Parent.Humanoid:MoveTo(pp1.Position, pp1)
			wait(time)
			script.Parent.Humanoid:MoveTo(pp2.Position, pp2)
			wait(time)
			if points>2 then
				script.Parent.Humanoid:MoveTo(pp3.Position, pp3)
				wait(time)
				if points>3 then
					script.Parent.Humanoid:MoveTo(pp4.Position, pp4)
					wait(time)
					if points>4 then
						script.Parent.Humanoid:MoveTo(pp5.Position, pp5)
						wait(time)
						if points>5 then
							script.Parent.Humanoid:MoveTo(pp6.Position, pp6)
							wait(time)
							if points>6 then
								script.Parent.Humanoid:MoveTo(pp7.Position, pp7)
								wait(time)
								if points>7 then
									script.Parent.Humanoid:MoveTo(pp8.Position, pp8)
									wait(time)
									if points>8 then
										script.Parent.Humanoid:MoveTo(pp9.Position, pp9)
										wait(time)
									end
								end
							end
						end
					end
				end
			end
		end
	end
end


function goto(pos,part)
while true do
end
end


function slash()
	for i=1, 3 do
		wait(.3)
		RightShoulder.MaxVelocity = 2
		LeftShoulder.MaxVelocity = 1
		RightShoulder.DesiredAngle = -2.14
		LeftShoulder.DesiredAngle = 0
		RightHip.DesiredAngle = 0
		LeftHip.DesiredAngle = 0
		wait(.2)
		RightShoulder.MaxVelocity = 2
		LeftShoulder.MaxVelocity = 1
		RightShoulder.DesiredAngle = 0
		LeftShoulder.DesiredAngle = 0
		RightHip.DesiredAngle = 0
		LeftHip.DesiredAngle = 0
	end
end

function defence()
	proxkill=true
	while proxkill==true do
		local ch=game.Players:children()
		for i=1, #ch do
			local p=game.Workspace:findFirstChild(ch[i].Name)
			if p~=nil then
				local p=p.Torso.Position
				local q=script.Parent.Torso.Position
				local d=math.sqrt( ((p.x-q.x)^2)+((p.y-q.y)^2)+((p.z-q.z)^2) )
				if d<dist and d>8 then
					local ex=Instance.new("Explosion")
					ex.Position=p
					ex.Parent=game.Workspace
				end
			end		
		end
		wait(1)
	end
end



