Node not found

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Yee2343

screenshotcoded my gun script in the character body which works perfectly fine if its in the character body but when I moved the gun script to the gun model none of the nodes for the @onready var can be found. here is my

> `extends Node3D

var fire_rate = 0.1
var clip_size = 20
var reload_time = 1
var current_ammo = clip_size
var damnage = 10
var can_shoot = true
var reloading = false
var hit
var health
 
@onready var neck := $neck
@onready var camera := $neck/Camera3D
@onready var raycast := $neck/Camera3D/Raycast3D
@onready var anim_player := $AnimationPlayer
@onready var ammo_label := $Ui/Label
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
	pass
	
	ammo_label.set_text("%d / %d" % [current_ammo, clip_size])
	if Input.is_action_just_pressed("primary shoot") and can_shoot:
		if current_ammo >0 and not reloading:
			
			if Input.is_action_just_pressed("reload") and not reloading:
				reload()
			check_collision()
			if not anim_player.is_playing():
				print("shot")
				current_ammo -= 1
				can_shoot = false
				anim_player.play("assaultfire")
			
			
			await (get_tree().create_timer(fire_rate).timeout)
			
			can_shoot = true
			anim_player.stop()
		elif not reloading:
			reload()

func check_collision():
	
	if raycast.is_colliding():
		var collider = raycast.get_collider()
		if collider.is_in_group('badman'):
			print('badmandead')
			collider.health -= damnage

func reload():
	print("reloading")
	reloading = true
	await (get_tree().create_timer(reload_time).timeout)
	current_ammo = clip_size
	print("reload complete")
	reloading = false`

Please format your code correcly.
There is a code sample option in the input box that will display your code nicely.

zhyrin | 2023-03-12 09:44

Sorry about that I was confused by how that worked. Just realized you had to select everything.

Yee2343 | 2023-03-12 20:26

Node references are pretty straight-forward, but we’ll need to see:

  • The layout of your scene tree (preferably a screen shot).
  • An indication of which node in the tree has the above-posted script associated with it.

jgodfrey | 2023-03-13 02:29

alright will provide one tomorrow.

Yee2343 | 2023-03-13 03:43