Invalid get index on base nil

Godot Version

4.2.2

Question

Hey, i am new to Godot and im trying to create a clicker game
I’m getting “invalid get index on base nil” error in this script:

@onready var main = %MainButton

var score = main.score

and click.gd script that attached to the MainButton object contains this:

var score = 0

how can i fix that error?

you already set the MainButton unique name?

yeah mine MainButton have unique name tag on it

at where do you put this line

not in _ready()?

no, that line is not in _ready()

extends Button

@onready var main = %MainButton`

var score = main.score

try change it to:

@onready var score = main.score

thanks! it worked

1 Like