print only shows Enemy1 in the output there is 6 enemies.. ive tried many different ways but doesnt work

local hud = script.Parent.Parent.Parent
local core = hud.Core
local enemies = hud.FightArea.Enemies
local team = hud.FightArea.Team
local enemy = hud.Enemy
local ally = hud.Ally
local enemyall = enemy:GetChildren()	
local enemyall2 = enemies:GetChildren()
	
		
	
	for i = 1,#enemyall do
		for i = 1,#enemyall2 do
		print(enemyall2[i])
	enemyall[i].Stats.HP.Changed:connect(function()
	if enemyall[i].Stats.HP.Value <0 then
		enemyall[i].Stats.HP.Value = 0
		hud.Dead.Enemy.Value = hud.Dead.Enemy.Value + 1
		if hud.Dead.Enemy.Value == 1 then
		core.Gold.Value = core.Gold.Value + core.GoldDrop.Value
		enemyall[i].Stats.HP.Value = enemyall[i].Stats.MaxHP.Value
		core.Kills.Value = core.Kills.Value + 1
		hud.Dead.Enemy.Value = 0
		if core.Kills.Value >= 10 then
			hud.FightArea.nextstage.Visible = true
			end
	end
	end
	
	end)
	
	while true do
		wait(0.1)
		enemyall2[i].HPBar.hptext.Text = enemyall[i].Stats.HP.Value
	hud.FightArea.Kills.Text = core.Kills.Value.."/".."10"
	enemyall2[i].HPBar.Bar:TweenSize(UDim2.new(enemyall[i].Stats.HP.Value/enemyall[i].Stats.MaxHP.Value,0,1,0), "Out", "Quad", 0, false)
	end
		end
		end

4 comments

0

try printing #enemies

0

the output is 6

0

fixed it by butted both 'end's before while true do

0

now when 1 enemy gets damaged all enemies get damaged suppose to be 1 at a time