You can get the location of the cursor at any time with getglobalmouse_position().
You can then compare that with the player's global position.
If the mouse's position is greater that the player's, it is on the right of the player and vice versa.
So you can do this in the player script:
if get_global_mouse_position().x > global_position.x:
scale.x = 1
elif get_global_mouse_position.x < global_position.x:
scale.x = -1
Additionally instead of changing the scale of the player you can just flip the sprite using $Sprite.flip_h = true/false if you want to. I hope this helped!