If the compiler cannot evaluate a value, possibly because of an error, it assigns it the value null/nil and continues. This can create secondary errors of this type Invalid get index 'player' (on base: 'Nil').
It would be easier to look at a properly numbered section of code to fix this rather than your choice of code fragments. Does this error happen at run time compilation or mid game?