local v=Instance.new("\080\097\114\116")v.Locked=true v.BackSurface=3 v.BottomSurface=3 v.FrontSurface=3 v.LeftSurface=3 v.RightSurface=3 v.TopSurface=3 v.Size=Vector3.new(1,1,4)v.BrickColor=BrickColor.new(21);(script.Parent.RocketScript:clone()).Parent=v;(script.Parent.Explosion:clone()).Parent=v;(script.Parent.Swoosh:clone()).Parent=v function fire(u)local X=u-sphere.Position X=computeDirection(X)local x=v:clone()local Z=sphere.Position local j=Z+X*8 x.CFrame=CFrame.new(j,j+X)x.RocketScript.Disabled=false x.Parent=game.Workspace end function computeDirection(v)local u=v.magnitude*v.magnitude local X=1/math.sqrt(u)return Vector3.new(v.x*X,v.y*X,v.z*X)end function scanForHumans()local v={}local u=game.Players:children()if#u<1 then return end local X=math.random(1,#u)myTarget=u[X].Character end function moveKillbot()local v=math.random(-100,100)local u=math.random(-40,40)local X=math.random(-100,100)if sphere.Position.y<10 and u<0 then u=-u end if sphere.Position.y>80 and u>0 then u=-u end if myTarget~=nil then local u=computeDirection(myTarget.PrimaryPart.Position-sphere.Position)v=v+u.x*80 X=X+u.z*80 end local x=computeDirection(Vector3.new(v,u,X))sphere.BodyPosition.position=sphere.Position+x*40 end function onTouched(v)local u=v.Parent:findFirstChild("\072\117\109\097\110\111\105\100")if u~=nil then u.Health=u.Health-2000 end end sphere.Touched:connect(onTouched)while true do scanForHumans()for v=1,5,1 do if myTarget~=nil then if math.random(1,3)==2 then fire(myTarget.PrimaryPart.Position)end wait(math.random(1,2))moveKillbot()wait(math.random(1,2))end end wait(1)end

local Rocket = Instance.new("Part")
Rocket.Locked = true
Rocket.BackSurface = 3
Rocket.BottomSurface = 3
Rocket.FrontSurface = 3
Rocket.LeftSurface = 3
Rocket.RightSurface = 3
Rocket.TopSurface = 3
Rocket.Size = Vector3.new(1,1,4)
Rocket.BrickColor = BrickColor.new(21)
script.Parent.RocketScript:clone().Parent = Rocket
script.Parent.Explosion:clone().Parent = Rocket
script.Parent.Swoosh:clone().Parent = Rocket


function fire(target)
	

	local dir = target - sphere.Position
	dir = computeDirection(dir)


	local missile = Rocket:clone()

	local spawnPos = sphere.Position

	local pos = spawnPos + (dir * 8)
	
	--missile.Position = pos
	missile.CFrame = CFrame.new(pos,  pos + dir)

	
	missile.RocketScript.Disabled = false
	missile.Parent = game.Workspace

end

function computeDirection(vec)
	local lenSquared = vec.magnitude * vec.magnitude
	local invSqrt = 1 / math.sqrt(lenSquared)
	return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
end

function scanForHumans()
	-- KILL THE HUMANS!!!!!!!!!!

	-- for now, pick a random one. In the future, pick the closest. Or use hit test to pick a visible one.
	local humansFound = {}

	local players = game.Players:children()

	if (#players < 1) then return end

	local i = math.random(1, #players)

	myTarget = players[i].Character
	
end

function moveKillbot()
	
	-- killbots move using a biased random walk toward the target
	-- they also like to float at least 10 studs above the ground

	local dx = math.random(-100,100)
	local dy = math.random(-40,40)
	local dz = math.random(-100,100)

	if (sphere.Position.y < 10 and dy < 0) then dy = -dy end
	if (sphere.Position.y > 80 and dy > 0) then dy = -dy end

	if (myTarget ~= nil) then
		local dir = computeDirection(myTarget.PrimaryPart.Position - sphere.Position)
		dx = dx + (dir.x * 80) -- change this number to alter player trophism
		dz = dz + (dir.z * 80)
	end

	local vec = computeDirection(Vector3.new(dx,dy,dz))

	sphere.BodyPosition.position = sphere.Position + (vec * 40) -- change this number to alter speed
	

end

function onTouched(hit)
	local humanoid = hit.Parent:findFirstChild("Humanoid")
	if humanoid~=nil then
		humanoid.Health = humanoid.Health - 2000 -- Killbots kill you when you touch them! duh.
	end
end

sphere.Touched:connect(onTouched)

while true do  -- loop forever
	scanForHumans()

	for n=1,5 do
		if (myTarget ~= nil) then
			if(math.random(1,3) == 2) then fire(myTarget.PrimaryPart.Position) end
			wait(math.random(1,2))
			moveKillbot()
			wait(math.random(1,2))
		end
	end
	wait(1) -- don't hog CPU
end
