Hello everyone. I recently moved all the code of a weapon inside the player script because I want it to interact with rng and I don't know how to do it otherwise. I have a bow that shoots where the mouse is at, I use a getglobalposition. The thing is, now that I've changed everything, when I try to shoot the project crashes with the error message you read on the title. I think that the issue itself is related to the fact that the code part that makes the weapon face towards the mouse is in the other script, if you know how to fix this, please let me know.
Here's the code from the bow (I just want it to face the mouse):
extends Node2D
func _process(delta: float) -> void:
look_at(get_global_mouse_position())
And here's the part of the player script that shoots the arrows, etc... :
extends Character
var arrow = preload("res://Arrowfinal.tscn")
var rubberarrow = preload("res://RuberArrow.tscn")`
if reroll == 1:
if Input.is_action_just_pressed("ui_attack") and current_weapon == 1 and can_fire:
var rubberarrow_instance = rubberarrow.instance()
rubberarrow_instance.position = $Arrowpoint.get_global_position()
rubberarrow_instance.rotation_degrees = rotation_degrees
$Arrow.play()
rubberarrow_instance.apply_impulse(Vector2().normalized(), Vector2(arrow_speed, 0).rotated(rotation))
get_tree().get_root().add_child(rubberarrow_instance)
can_fire = false
yield(get_tree().create_timer(fire_rate), "timeout")
can_fire = true