MV hidding unactive party members

ok so I'm trying to do what is a staple in almost every single player rpg out there where you can gather party members and all that. by default MV shows every person in the menu list regardless of if there in the active party or not. Far as i know there is no plugin that alters this at least i haven't found one. i did find this after digging around
Code:
Window_MenuStatus.prototype.maxItems = function() {
return $gameParty.maxBattleMembers();
};

this "does" work sorta it works if there are more than x number of party members in your party (whatever you have the number set to 4 5 6 or more or less w/e) but if you have less than what is set it crash`s the game. so someone with more JS knowledge if you could maybe help get this to hide all inactive party member (those who are not in battle) and not crash the game if there are less then 4 or whatever you have battle numbers set to (for my game its set to 6 atm) so if there is less then 6 in my party if i open the menu it crashes`s the game

a little more info I'm using yanfly party manager Aswell so i want it to hide inactive members but still be able to see them in the party manager to switch them in and out of active party

the code above does exactly what i want just i don't want it to crash if there's less then 6 in the party xD lol... as you don't start with any party members and gain them as you progress

thank you in advance :x

crash log that pops up if there's less then 6 in party

Original thread: https://forums.rpgmakerweb.com/threads/hidding-unactive-party-members.149423/