FloatingFortressChaseScript

nodescrtiptionavailable
 avatar
unknown
lua
2 years ago
1.8 kB
7
Indexable
local larm = script.Parent:FindFirstChild("Left Arm")
local rarm = script.Parent:FindFirstChild("Right Arm")
local waitTimer = 0

function findNearestTorso(pos)
	local list = game.Workspace:children()
	local torso = nil
	local dist = 7500
	local temp = nil
	local human = nil
	local temp2 = nil
	for x = 1, #list do
		temp2 = list[x]
		if (temp2.className == "Model") and (temp2 ~= script.Parent) then
			temp = temp2:findFirstChild("Torso")
			human = temp2:findFirstChild("Humanoid")
			team = temp2:findFirstChild("TEAM")
			if (temp ~= nil) and (human ~= nil) and (human.Health > 0) and (team ~= nil) and (team.Value ~= script.Parent.TEAM.Value) then
				if (temp.Position - pos).magnitude < dist then
					torso = temp
					script.Parent.Target.Value = temp
					dist = (temp.Position - pos).magnitude

					if human.Health >= 1 then 
					script.Parent.Range.Value = true 
					else 
					script.Parent.Range.Value = false 
					end 
				end
			end
			if dist < 50 then 
				script.Parent.Humanoid.WalkSpeed = 0
				script.Parent.Attack.Value = true 
			else 
				script.Parent.Humanoid.WalkSpeed = 17
				script.Parent.Attack.Value = false 
			end 
		end
	end
	return torso
end

function Sit()
	if script.Parent.Humanoid.Sit == true then 
		script.Parent.Humanoid.Jump = true 
		print("Anti Seat Putter!!!")
	end 
end 

script.Parent.Humanoid.Changed:connect(Sit)

while true do
	wait(1)
	local target = findNearestTorso(script.Parent.Torso.Position)
	if target ~= nil then
		rx = math.random(0,0)
		ry = math.random(0,0)
		rz = math.random(0,0)
		script.Parent.Humanoid:MoveTo(target.Position+Vector3.new(rx,ry,rz), target)
	else 
		script.Parent.Range.Value = false 
		script.Parent.Attack.Value = false 
	end
end
Editor is loading...