Index error while following a tutorial

Godot Version



While following a reasonably recent tutorial (

to make a snake style game, I’ve run into an error.

“Invalid set index ‘position’ (on base: ‘Aread2D (Head)’) with value type ‘Vector2’.”

None of the stuff I’ve found has given me a good explanation of what causes this error, or how i can fix. I’ve gone back pretty meticulously and can’t find any differences between my code and the guy on the screens. But his works, and mine doesn’t

I have a script called “” to make a class called “SnakePart”. It looks like this:

extends Area2D

var last_position:Vector2

func move_to(new_position:Vector2):
	last_position = self.position
	self.positon = new_position

This script interacts with two functions in my main gameplay script, which look like this:

func _physics_process(delta: float):
	time_since_last_move += delta * speed
	if time_since_last_move >= time_between_moves:
		time_since_last_move = 0

func update_snake():
	var new_pos: Vector2 = head.position + move_dir * Global.GRID_SIZE

the var “head” is declared at the top of the gameplay script:

@onready var head: Head = $Head as Head

and that class “Head” extends “SnakePart” from earlier, meaning its an Area2D with an extra var and function available

I really don’t understand what could be going wrong, or what the error is trying to tell me. I’ve combed through it several times for typos and haven’t found any, so i really don’t understand why its having this issue. Has something changed about these functionalities in the last month since this tutorial came out? Or are my eyes just too tired to see what im missing?

The error message is consistent with incorrect initialisation. Hard to see from your code, but check that head variable is actually initialised before modifying it. I quick “if head != null” before updating will tell you that

Never mind.
Its a spelling error


You should copy the error message rather than type it out.
PS: I make this same typo commonly.