You’re welcome, because it has to refresh every time you kill the enemy. Once you kill it, enemy would be none, so if you have it in the while loop, it will always have the nearest enemy, if it is outside, it would find the nearest at the beginning of the level and ignore the rest