Instance in godot 4.0 re5

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

I wanted to ask how to create a node
in godot 4.0 re 5
var instance = load(“res://item.res”)
var spawn = instance.instance()

but does not work
please HELP

:bust_in_silhouette: Reply From: xk

var instance = load(“res://item.res”)
var spawn = instance.instantiate()

extends Node2D

var direction:int = 0
var speed:int = 450
var half_of_player:int = 15
var bullet_scene = preload(“res://scenes/bullet.tscn”)
var bullet_time = 0.5
var bullet_spawn = 0

Called when the node enters the scene tree for the first time.

func _ready():
pass # Replace with function body.

Called every frame. ‘delta’ is the elapsed time since the previous frame.

func _process(delta):
bullet_spawn += delta

if Input.is_action_pressed("shoot") and bullet_spawn> bullet_time:
	var bullet_instance = bullet_scene.instantiate()
if Input.is_action_pressed("move_left"):
	direction = -1
elif Input.is_action_pressed("move_right"):
	direction = 1
	direction = 0

position.x = clamp(position.x + direction * speed * delta, half_of_player,400- half_of_player )

this code is not working
help please