You should show the full code. There could be things that you removed which would be causing the problem.
Also, I noticed you create a new "player" variable even though one is already passed to the function.
Rename the one in the function header so they aren't confused.