You need to check if the user is connected for both situations (the if and the else if) but should be checked only once before everything else. However, there may be bigger issues because player should, idealy, never be 0. You will get the best solution by posting the whole code.