Change leader image with script

Hey there people!

So I have an event that changes the image of the leader into a cat so that he can crawl through small spaces.

I'm using scripts to make the s event, but how I chang the leader back to what he's supposed to be?

Here's my script
Script:
PrevImage = $gamePartyleader()._characterName;
PrevIndex = $gamePartyleader()._characterIndex;

Script:
$gamePartyleader().setCharacterImage("horse",0);
$gamePlayer.refresh()

Script:
$gamePartyleader().setCharacterImage(PrevImage,PrevIndex);
$gamePlayer.refresh()

It works on the changing of the leader image but it doesn't change it back. What am I doing wrong?
variables defined in an event command script box get deleted when the script box is closed.
That is part of the sandboxing of scripting.

you need to store the info outside the script command, in the game variables to be able to get the data in another script command.
variables defined in an event command script box get deleted when the script box is closed.
That is part of the sandboxing of scripting.

you need to store the info outside the script command, in the game variables to be able to get the data in another script command.
Okay that makes sense...
Do you know how I can use a variable in a script box?
just use the script code for the variables, it is listed in the script equivalents for event commands a pinned topic on the forum somewhere)
If it's all done within the same sequence and the player doesn't get to do anything until it's finished, you could just make the player transparent and use an event instead. You just have to make the event and the player move together, which is easy enough, so the map scrolls correctly.

Original thread: https://forums.rpgmakerweb.com/threads/change-leader-image-with-script.143347/