Node2D rotation follow player

Godot Version

4.3

Question

I need help, I’ve been 4 hours trying to program a bot and nothing works. I want to make the rotation of the Node2D to follow the player but I don’t know how to do it

extends Node2D

@onready var bullet_scene = preload("res://Resources/bullet.tscn")
@onready var marker_2d: Marker2D = $Marker2D
@onready var player = preload("res://player.tscn")
var player_instance
var last_shoot_time

func _ready():
	pass
func _process(delta: float) -> void:
	if player != null:
		player_instance = player.instantiate()
		look_at(player_instance.global_position)
		rotation_degrees = wrap(rotation_degrees, 0, 360)
		rotation()

func rotation():
	if rotation_degrees > 90 and rotation_degrees < 270:
		scale.y = -0.2
	else:
		scale.y = 0.2
	
func shoot():
	var bullet = bullet_scene.instantiate()
	get_tree().root.add_child(bullet)
	bullet.global_position = marker_2d.global_position
	bullet.rotation = rotation
	
	last_shoot_time = 0

the problem is that you instantiate your own player instead of referencing your existing one.
There are multiple ways to workaround this. One way is to use groups:
go to the player and add it to a global group called “player”.
Then go to your node2d-script and put this in there:

var player

func _ready():
    player = get_tree().get_nodes_in_group("player")[0]