How to get variable from other scene?

(new to coding and programming)
So… I have a turret and when the turret instantiates a bullet, the game crashes D:

# this is the script of the bullet
func _ready():
	rotate_number = get_tree().get_root().get_node("turret").get("random_number")

Other nodes may not be ready by the time this node is _ready()

turret must be a global for it to be a child of root, maybe you could use get_tree().current_scene but maybe an export variable would be better?

@export var turret: Node
# assign export variables from the Inspector

func _ready():
	rotate_number = turret.random_number

Thanks! : )
But one small problem, how do I assign it to the node of another scene?

Somehow I missed it was being instantiated by the turret.

Sorry, @export is only particularly useful for editor-created nodes. Still you can use a turret variable and assign it during instantiation.

func shoot() -> void:
    var new_bullet = BULLET.instantiate()
    new_bullet.turret = self # assigning turret
    new_bullet.position = position
    add_sibling(new_bullet)

I get this error when the shoot function gets called


Code that gets error:

	new_bullet.Corrupted_fish = self # assigning turret

I feel like at this point I should just reset my cursed turret scene because I even tried using call_group functions or whatever they are called:

	get_tree().call_group("Bullet", "Set_variable_1")

And it ended up working for the bullet calling a damage function on the player, but it does not work for the turret calling a function for the dammed bullet.

Should I just try deleting the turret and bullet script and rework it?

Seems like the wrong error, your variable is named Corrupted_fish for the turret? But the error says you tried new_bullet.Turret = something. What is the var turret on your bullet? use that variable name with the `new_bullet.

# If bullet.gd has this definition
var owning_turret_that_shot_me

# Then the turret.gd needs to access it
var new_bullet = BULLET.instantiate()
new_bullet.owning_turret_that_shot_me = self

Really hard to assess without the full script. I highly recommend pasting the turret script (at least the instantiating bullets part) and the entire bullet script.

Spawning a bullet should be a very small amount of code, no need to scrap any greater turret code over this one part.

I will just continue of your advice and stop bothering you, thanks for everything.