This needs to go after the player has been set. In the case that they specify a player, but this is running from console, p will be null at this point, but should be set after line 442, which is where this check should go.