Probably It's the game that give's the invalid. I'm not coding and I don't know how to code, but it will make more sense since you are looking for a slot and the game returns **invalid** as there is no player. My best suggestion to make a player list that will only show the players online, and not a full list with invalid. like if there is only 2 players then only 2 slots appears:
Nig1337Nog
BlasterMaster
and not:
Nig1337Nog
**invalid**
**invalid**
**invalid**
**invalid**
**invalid**
Get me ?