onready var pistol = getnodeornull("Headposition/Glock 2021")
onready var Pistol = preload("res://Glock 2021.tscn").instance()
onready var headpos = getnode("Head_position")
var gun = false
var current_weapon = 1
func weaponselect():
if Input.isactionjustpressed("Pistol"):
currentweapon = 1
if Input.isactionjustpressed("Submachinegun"):
currentweapon = 2
if Input.isactionjustpressed("Shutgun"):
currentweapon = 3
if Input.isactionjustpressed("Assultrifle"):
currentweapon = 4
if Input.isactionjustpressed("Sniperrifle"):
currentweapon = 5
if Input.isactionjustpressed("Rocketlauncher"):
currentweapon = 6
if current_weapon == 1 and pistol == null:
head_pos.add_child(Pistol)
elif current_weapon != 1 and pistol != null :
pistol.queue_free()
func process(delta):
weaponselect()
if i run this code ecerything works just fine as long as i dont press other number than 1 after that it shows me "queefree" in an "nullinstance" as long as i understand that code is running every frame so queue free as well i dont know how to make queue_free only once pls help