follow.Event:Connect((require(enemyFunctions)).Follow)while true do local v={}for o,F in pairs(players:GetChildren())do if F.Character and(F.Character:FindFirstChild("\072\117\109\097\110\111\105\100")and F.Character.Humanoid.Health>0)then if F:FindFirstChild("\083\116\097\116\115")and(F.Stats:FindFirstChild("\067\117\114\114\101\110\116\065\114\101\097")and F.Stats.CurrentArea.Value)then local o=F.Stats.CurrentArea.Value:FindFirstChild("\069\110\101\109\105\101\115")if o then for o,F in pairs(o:GetChildren())do if not table.find(v,F)then table.insert(v,F)end end end end end end for v,o in pairs(v)do local F=(require(enemyFunctions)).FindClosestPlayer(o,true)if F then if F.Character then local v=F.Character:FindFirstChild("\072\117\109\097\110\111\105\100\082\111\111\116\080\097\114\116")if v then follow:Fire(o,v)end end elseif o:FindFirstChild("\083\116\097\116\115")and o.Stats:FindFirstChild("\079\114\105\103\105\110\097\108\080\111\115\105\116\105\111\110")then o.EnemyHumanoid:MoveTo(o.Stats.OriginalPosition.Value)end end wait()end

follow.Event:Connect(require(enemyFunctions).Follow)

while true do
	local enemiesToConsider = {}
	for _,player in pairs(players:GetChildren()) do -- Adds all enemies in loaded areas to the considered table
		if player.Character and player.Character:FindFirstChild("Humanoid") and player.Character.Humanoid.Health > 0 then
			if player:FindFirstChild("Stats") and player.Stats:FindFirstChild("CurrentArea") and player.Stats.CurrentArea.Value then
				local enemiesFolder = player.Stats.CurrentArea.Value:FindFirstChild("Enemies")
				if enemiesFolder then
					for _,enemy in pairs(enemiesFolder:GetChildren()) do
						if not table.find(enemiesToConsider, enemy) then
							table.insert(enemiesToConsider, enemy)
						end
					end
				end
			end
		end
	end
	for _,enemy in pairs(enemiesToConsider) do
		local closestPlayer = require(enemyFunctions).FindClosestPlayer(enemy, true)
		if closestPlayer then
			if closestPlayer.Character then
				local rootPart = closestPlayer.Character:FindFirstChild("HumanoidRootPart")
				if rootPart then
					follow:Fire(enemy, rootPart)
				end
			end
		elseif enemy:FindFirstChild("Stats") and enemy.Stats:FindFirstChild("OriginalPosition") then
			enemy.EnemyHumanoid:MoveTo(enemy.Stats.OriginalPosition.Value)
		end
	end
	wait()
end
