Menu

Common GDScript Errors and How to Fix Them

The GDScript errors beginners meet most, with the exact Godot 4 message, what it means and the fix: null instance, Nil, not declared in the current scope, invalid index, indentation, invalid operands and node not found.

This page includes runnable editors. Edit, run, and see output instantly.

Godot reports two kinds of errors. A parse error is found before anything runs, in the code itself, and the script does not start. A runtime error happens while the game runs, and stops the function where it happened. Both name the file and line, as in res://main.gd:7.

Most runtime errors on this page come from a value that was not what the code expected. These checks prevent the common ones:

0
true

Invalid call. Nonexistent function '...' in base 'Nil'

SCRIPT ERROR: Invalid call. Nonexistent function 'queue_free' in base 'Nil'.

Meaning: you called a method on null. Nil is the type of null.

Fix: find out why the variable is empty. Common causes: a function that returned nothing, an @export node you never set in the Inspector, or a lookup that failed. Guard with if target: or is_instance_valid().

The same problem reading a property says Invalid access to property or key 'position' on a base object of type 'Nil'.

... on a base object of type 'null instance'

ERROR: Node not found: "Label" (relative to "/root/Main").
SCRIPT ERROR: Invalid assignment of property or key 'text' with value of type 'String' on a base object of type 'null instance'.

Meaning: $Label or get_node("Label") found no node with that path, so it gave null, and the next line used it. The first line tells you which path failed and where the search started.

Fix: check the spelling and capitals against the Scene dock, check that the node is a child of the node running the script, and check that the code runs in _ready() or later. Use %Label (a unique name) or an @export variable so moving the node does not break the path. See the scene tree.

Identifier "..." not declared in the current scope

Parse Error: Identifier "scor" not declared in the current scope.

Meaning: Godot does not know this name here.

Fix: look for a typo first (scor and score). Then check where the variable is declared: a var inside one function or inside an if block does not exist in another. Move it to the top of the script to make it a member variable. A similar message, Function "jump()" not found in base self., means a method name is wrong or missing.

Out of bounds get index

SCRIPT ERROR: Out of bounds get index '2' (on base: 'Array')
          at: _ready (res://main.gd:6)
          GDScript backtrace (most recent call first):
              [0] _ready (res://main.gd:6)

Meaning: the array has no item at that index. Indexes go from 0 to size() - 1, so an array of 2 has indexes 0 and 1. When the variable has no static type, the same mistake reads Invalid access of index '2' on a base object of type: 'Array'.

Fix: check if i < items.size():, loop with for item in items instead of counting, or use items.back() for the last item. For dictionaries the message is Invalid access to property or key 'mana' on a base object of type 'Dictionary'., and get(key, default) avoids it.

Indentation Errors

Parse Error: Used tab character for indentation instead of space as used before in the file.
Parse Error: Expected indented block after "if" block.
Parse Error: Unexpected "Indent" in class body.

Meaning: blocks are defined by indentation, and this indentation is wrong.

  • The first one mixes tabs and spaces in one file, usually from pasted code. In the Godot script editor, use Edit > Indentation > Convert Indent to Tabs.
  • The second one has an if, for or func line with nothing indented under it. Indent the body, or write pass.
  • The third one is often a missing : at the end of a func, if or for line, which makes the next indented line unexpected.

Invalid operands

Parse Error: Invalid operands to operator +, String and int.
SCRIPT ERROR: Invalid operands 'String' and 'int' in operator '+'.

Meaning: the operator does not work on these two types. Usually text and a number joined with +.

Fix: convert with str(), or use formatting: "Score: " + str(score) or "Score: %d" % score. See string formatting.

Trying to assign value of type ... to a variable of type ...

SCRIPT ERROR: Trying to assign value of type 'String' to a variable of type 'int'.

Meaning: a typed variable received the wrong type, usually from a dynamic value such as data read from a file. Fix: convert first (int(text)) or check the type with is. See static typing.

... on a base object of type 'previously freed'

SCRIPT ERROR: Invalid assignment of property or key 'name' with value of type 'String' on a base object of type 'previously freed'.

Meaning: the object was deleted (with queue_free() or free()), but a variable still pointed at it. Fix: check is_instance_valid(node) before using a stored reference, and clear references when the node leaves the tree.

Too few arguments

Parse Error: Too few arguments for "take_damage()" call. Expected at least 2 but received 1.

Meaning: the call passes fewer values than the function needs. Fix: pass them all, or give the missing parameters default values in the function.

Godot 3 Code in Godot 4

Errors such as "yield" was removed in Godot 4. Use "await" instead. or The "export" keyword was removed in Godot 4. mean the code was written for Godot 3. Replace yield with await, export var with @export var, onready var with @onready var, and string-based connect("signal", self, "method") with signal.connect(method).

Frequently Asked Questions

What does "null instance" mean in Godot?

Your code used a node or object that is not there: the variable holds null. Usually a $Path or get_node() did not find the node (a typo, a rename, or a different scene layout), or the variable was read before _ready(). Check the node path in the Scene dock first.

What does "not declared in the current scope" mean?

Godot does not know the name. It is misspelled, it was declared inside another function or block, or it is a variable from Godot 3 or another tutorial that your script does not have. Declare it with var where every line that uses it can see it.

Does a GDScript error crash the whole game?

When you run from the editor, the debugger pauses on the failing line. In an exported game, the function with the error stops and the game carries on, which often leaves things half done. Fix errors rather than relying on that.

What is the difference between a parse error and a runtime error?

A parse error is found before the script runs, from the code alone: a missing colon, a wrong indent, an undeclared name, a type mismatch Godot can see. The script does not run at all. A runtime error happens while the game runs, on a value Godot could not check in advance, such as null or an index past the end.

Coddy programming languages illustration

Learn to code with Coddy

Get started