So I'm at the end of my turn-based combat script, and one of the most crucial features isn't working: the player actually winning when he kills the enemy.
I have 2 in pairs loops and when the player kills the enemy, it's supposed to do this code. (The Below code is the in pairs loop)
for i,v in pairs(game.Workspace:GetChildren()) do
local CurrentEnemyName = CombatGui.CurrentEnemyName
if v == CurrentEnemyName.Value then
local enemy = v
local eHumanoid = enemy:WaitForChild("Humanoid")
if eHumanoid.Health == 0 then
Status.Value = "You Won!"
print(Status.Value)
wait(5)
enemy:BreakJoints()
CombatGui.Enabled = false
CombatGui.Parent.PlayerHealth.Enabled = false
gainHealth.Visible = true
takeDamage.Visible = true
Hum.Health = 100
Status.Value = ""
wait(5)
enemy:Destroy()
debounce=false
end
if eHumanoid.Health <0 then
eHumanoid.Health = 0
end
end
end
If ya'll have any idea why it won't register, please tell me. Thanks.

1 comment
Where do you call the loop? if you called it before the instance you want in the game has been placed there, then it would not be registered as one of the "v"