Is global_position defined anywhere in your project? You can't use a variable unless it's declared and initialized.
What's the purpose of this line?
var direction = sign(player.global_position.x - global_position.x)
If direction is not used, you can remove that line.