Set Immortality after Transform

I have a boss monster which transforms in mid battle. I put the immortal status on it, in the first form, but after the transform the status is gone. I try to put it on in a battle event, but it does not seem to apply to the second form.

Here's the transform, which works.

◆Script:var enemyIndex = $gameVariables.value(1) - 1; //Troop index
:Script:var enemyFromId = $gameVariables.value(2);
:Script:var enemyIntoId = $gameVariables.value(3);
:Script:var enemy = $gameTroop.members()[enemyIndex];
:Script:var flickerCount = 0;
:Script:
:Script:function flickerTransform()
:Script:{
:Script: if (flickerCount <= 7)
:Script: {
:Script: //Alternate between temporary and final forms
:Script: if (flickerCount % 2 === 0)
:Script: {
:Script: enemy.transform(enemyFromId);
:Script: }
:Script: else
:Script: {
:Script: enemy.transform(enemyIntoId);
:Script: }
:Script: //Wait for x milliseconds
:Script: setTimeout(() =>
:Script: {
:Script: flickerCount++;
:Script: flickerTransform();
:Script: }, 250);
:Script: }
:Script:}
:Script:
:Script:flickerTransform();

After the Transform I try to apply the Immortal state again, but the enemy name (RoastPumpkin) isn't in the dropdown list, so I use the enemy ID #1, which is the original boss:

◆Change Enemy State:#1 Pumpkinhead, + Immortal
◆Change Enemy State:#1 Pumpkinhead, + Guard
◆Change Enemy State:#1 Pumpkinhead, + HP Regeneration

However, it is not applying the states. I suspect the transform is generating a new enemy ID, which doesn't exist yet when I code in the Change State commands. How do I apply the Immortal state to the second form?
Well if I transform an enemy it holds the state and also a state can be added to it from a troop event by referencing the original. What's the point of the scripts? Can't you control the transformation from troop events?
Well if I transform an enemy it holds the state and also a state can be added to it from a troop event by referencing the original. What's the point of the scripts? Can't you control the transformation from troop events?
You're right; the state seems to be holding after the transform now. No idea why it wasn't before. I also applied Poison so I had a state I could see working, and that didn't show up either.

The point of the script is to have a common resource I can reuse. I want to have the enemy flicker between the two transform forms before settling on the final one, rather than just appearing out of nowhere. I ended up tweaking it so much it was a pain to replicate.

Original thread: https://forums.rpgmakerweb.com/threads/set-immortality-after-transform.175283/