Checking for target AC with roll to hit event

I’ve tried Azure Yoshi’s Roll to Hit Tutorial, but I am running into a snag. When an enemy is reduced to 0 HP and a new enemy is autotargeted on that turn, the new enemy’s ID comes up as 1 and its AC is either 0 or whatever default AC has been specified. How do I make it so that the battle system can check a target variable (in this case, the new enemy’s AC) on the fly?
Just to put my two cents in, I don't think this is a very good way to implement what you're looking for.

It's overly complicated and, as you see, can produce unexpected results with the actual code of the battle system.

I would suggest much more simply using a plugin that can alter the math used to hit enemies. caethyril has one in her MZ plugins, and I have one here:

That way you're not trying to outsource your entire combat system into common events and the engine's code should just work more naturally.
Thank you for the quick reply and elegant solution, @ATT_Turan.

Original thread: https://forums.rpgmakerweb.com/threads/checking-for-target-ac-with-roll-to-hit-event.158014/