Variable Scope Error Godot 4.2

Godot Version

Question

extends Node2D

var speed = 100

@onready var path_follow: PathFollow2D = $Path2D/PathFollow2D

func _ready():
var enemy = preload(“res://Mobs/soldier A.tscn”)
var enemy_instance = enemy.instantiate()
add_child(enemy_instance)

func _process(delta):
path_follow.offset += speed * delta
enemy_instance.position = path_follow.position

this code is error

enemy_instance.position = path_follow.position

my goal is create instance to moving follow tha PathFollow2d

change to this:

extends Node2D

var speed = 100

@onready var path_follow: PathFollow2D = $Path2D/PathFollow2D

var enemy_instance 

func _ready():
	var enemy = preload("res://Mobs/soldier A.tscn")
	enemy_instance = enemy.instantiate()
	add_child(enemy_instance)

func _process(delta):
	if enemy_instance:
		path_follow.offset += speed * delta
		enemy_instance.position = path_follow.position
1 Like

Thank you it’s work.

my instance appears but not moving I try to figure it by myself.