Invalid call. Nonexistent function "instance" in base "Pathfollow2D"

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

Hi I’m new in Godot and I was trying the tutorial for Dodge the creeps, but it gives me this error Invalid call. Nonexistent function “instance” in base “Pathfollow2D”, i already check that the PackedScene is in the inspector, this is the code:

extends Node

export (PackedScene) var Mob
var score

func _ready():
	randomize()
	

func game_over():
	$ScoreTimer.stop()
	$MobTimer.stop()
	$HUD.show_game_over()

func new_game():
	score = 0
	$Player.start($StartPosition.position)
	$StartTimer.start()
	$HUD.update_score(score)
	$HUD.show_message("Get Ready")


func _on_MobTimer_timeout():
	$MobPath/MobSpawnLocation.set_offset(randi())
	var Mob = Mob.instance()
	add_child(Mob)
	var direction = $MobPath/MobSpawnLocation.rotation + PI /2
	direction += rand_range( -PI/4, PI/4)
	Mob.rotation = direction
	Mob.linear_velocity = Vector2(rand_range(Mob.MIN_SPEED, Mob.MAX_SPEED), 0)
	Mob.linear_velocity = Mob.linear_velocity.rotated(direction)


func _on_ScoreTimer_timeout():
	score += 1
	$HUD.update_score(score)


func _on_StartTimer_timeout():
	$MobTimer.start()
	$ScoreTimer.start()

the engine tell me that the problem is in this line: var Mob = Mob.instance(), anyone knows what is wrong with the code?

When you do a Mob.instance() you get an instance of the Mob scene returned. So you don’t want to overwrite Mob variable. Instead in on_MobTimer try doing var mob = Mob.instance() (lowercase mob). And then in the same function change the Mob to mob everywhere.

gmaps | 2019-09-17 08:04