Maybe this thread could be renamed the "official loop scope issue" thread? I have another one that I've been struggling with.
I have a shooter game where I want damage counters to show the total damage taken by enemies. These counters (black ones) pop up over their heads and disappear after 1 second after the last hit. When the enemy is killed the counter is destroyed and replaced by another counter that show the "final damage" (blue ones). The problem I have is that SOMETIMES "ghost counters" appear under the black counters, as if the pairing of ID to fixed value is lost and prevents the counter from following the hit enemy. However, the counter isn't stuck, there just seems to be another counter created under it and left in place since it shows up in the debugger. Might be a scope issue with the "counterCool" value that should make it disappear, but none of the counters seem to be reset. It's is kind of hard to recreate this.
This image shows the ghost counters, enemies have been killed.
The damageRoll flag means that the enemy has been hit and has a counter. DamageRoll for the "cha" object is unrelated. The counter is created on first hit and added to while hit again (addToCounter loop).
The blue counter is created when the counters' respective enemy has HP 0. Old counter is destroyed. (The counter add furthest down is unrelated).
The counter should follow it's enemy and is destroyed when counterCool or Hp is 0.
Any help greatly appreciated!