i think its not the point:
"while (!player){ wait(1); } "
...that means the function does not start without the player?!