Think of it logically, when you interact, the character will move closer to the npc and attack it. In the time that it takes to do that, the script already passed the conditional sleep because it's not yet under attack the millisecond after it interacts