The error says that the player is not valid, it can mean that user with Index '5' doesn't not exit or (i'm not sure at this hour because i'm very sleepy) it is not alive, as CrazY say you can add an is_user_alive() filter.
But i'm giving you an friendly advice and say that you should give-up checking for players with this method:
PHP Code:
for(new id = 1; id < g_iMaxPlayers; id++)
{
Better use get_players() also in that way you can also use the flag "a" and leave is_user_alive().
__________________