function BEGINAI()HUMANOID.Died:Connect(function()DEAD=true script:Remove()end)coroutine.resume(coroutine.create(function()repeat wait()local A={}local o=nil for o,c in pairs(workspace:GetDescendants())do local U=c:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")if U and c:FindFirstChild("\077\105\110\101\099\114\097\102\116\072\101\114\111\098\114\105\110\101\077\097\105\110\083\099\114\105\112\116")==nil then if U.Health~=0 then if U.Torso then local o=(U.Torso.Position-TORSO.Position).Magnitude table.insert(A,{c;o})end end end end local c=math.huge for U=1,#A,1 do local f=A[U]local R=f[1]local X=f[2]if X<c then c=X o=R end end TARGET=o if TURNTO then GYRO.CFrame=CF(FAKEHEAD.Position,TURNTO.Position+VT(0,TURNTO.Size.Y/1.5,0))else GYRO.CFrame=HEAD.CFrame end until DEAD==true end))while true do if DEAD==true then break end if TARGET then local A=TARGET:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")if A then local o=A.Torso if o then local c=(game:GetService("\080\097\116\104\102\105\110\100\105\110\103\083\101\114\118\105\099\101")):ComputeRawPathAsync(TORSO.Position,o.Position,2)if c then local U=TARGET TURNTO=o local f=c:GetPointCoordinates()local R=TORSO.Position local X=#f>1 and 2 or 1 for c=X,#f,1 do local R=f[c]local X=math.huge repeat wait(.1)X=(TORSO.Position-R).Magnitude HUMANOID:MoveTo(R)if(o.Position-TORSO.Position).Magnitude<7 then StabAnim()ApplyDamage(A,A.MaxHealth/20)local c=IT("\083\111\117\110\100",o)c.SoundId="\114\098\120\097\115\115\101\116\105\100\058\047\047"..HITSOUNDS[MRANDOM(1,#HITSOUNDS)]c.Parent=o c.Pitch=1 c.Volume=1.5 c:Play()Debris:AddItem(c,2)if A.Health==0 then break end wait(.4)end until X<5 or TARGET~=U if TARGET~=U then break end end else TURNTO=nil end else TURNTO=nil end else TURNTO=nil end else TURNTO=nil end wait()end end BEGINAI()


function BEGINAI()
	HUMANOID.Died:Connect(function()
		DEAD = true
		script:Remove()
	end)
	coroutine.resume(coroutine.create(function()
		repeat
			wait()
			local TARGETVARIANTS = {}
			local PICK = nil
			for index, CHILD in pairs(workspace:GetDescendants()) do
				local HUMAN = CHILD:FindFirstChildOfClass("Humanoid")
				if HUMAN and CHILD:FindFirstChild("MinecraftHerobrineMainScript") == nil then
					if HUMAN.Health ~= 0 then
						if HUMAN.Torso then
							local DISTANCE = (HUMAN.Torso.Position - TORSO.Position).Magnitude
							table.insert(TARGETVARIANTS,{CHILD,DISTANCE})
						end
					end
				end
			end
			local DIST = math.huge
			for E = 1, #TARGETVARIANTS do
				local PLAYER = TARGETVARIANTS[E]
				local CHARACTER = PLAYER[1]
				local DISTANCE = PLAYER[2]
				if DISTANCE < DIST then
					DIST = DISTANCE
					PICK = CHARACTER
				end
			end
			TARGET = PICK
			if TURNTO then
				GYRO.CFrame = CF(FAKEHEAD.Position,TURNTO.Position+VT(0,TURNTO.Size.Y/1.5,0))
			else
				GYRO.CFrame = HEAD.CFrame
			end
		until DEAD == true
	end))
	while true do
		if DEAD == true then
			break
		end
		if TARGET then
			local HUM = TARGET:FindFirstChildOfClass("Humanoid")
			if HUM then
				local ROOT = HUM.Torso
				if ROOT then
					local PATHFIND = game:GetService("PathfindingService"):ComputeRawPathAsync(TORSO.Position,ROOT.Position,2)
					if PATHFIND then
						local FOE = TARGET
						TURNTO = ROOT
						local PS = PATHFIND:GetPointCoordinates()
						local PREV = TORSO.Position
						local BR = #PS > 1 and 2 or 1
						for i = BR,#PS do
							local POINT = PS[i]
							local DIST = math.huge
							repeat wait(0.1)
								DIST = (TORSO.Position - POINT).Magnitude
								HUMANOID:MoveTo(POINT)
								if (ROOT.Position - TORSO.Position).Magnitude < 7 then
									StabAnim()
									ApplyDamage(HUM,HUM.MaxHealth/20)
									local HIT = IT("Sound",ROOT)
									HIT.SoundId = "rbxassetid://"..HITSOUNDS[MRANDOM(1,#HITSOUNDS)]
									HIT.Parent = ROOT
									HIT.Pitch = 1
									HIT.Volume = 1.5
									HIT:Play()
									Debris:AddItem(HIT,2)
									if HUM.Health == 0 then
										break
									end
									wait(0.4)
								end
							until DIST < 5 or TARGET ~= FOE
							if TARGET ~= FOE then
								break
							end
						end
					else
						TURNTO = nil
					end
				else
					TURNTO = nil
				end
			else
				TURNTO = nil
			end
		else
			TURNTO = nil
		end
		wait()
	end
end

BEGINAI()
