Sorry, your script is way too messed up (and you overcomplicated it way too much). I can't figure out what it does in short time so I'm giving up on it.
As for the caterpillar, I noticed that you are turning it on/off somewhere. You should probably take a look at that. The caterpillar only appears on the map which means it requires Spriteset_Map.