invalid set index 'text' (on base 'null instance') with value of type 'string'

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

Hello ,

I just watched this tutorial Tutorial and followed everything he did to make inventory and item system.I swear i checked code thousand times already but still im getting same error invalid set index ‘text’ (on base ‘null instance’) with value of type ‘string’ and cant launch scene.

the code looks like this:

we have .json file
“Tree Branch”: {
“ItemCategory”: “Resource”,
“StackSize”: 99,
“Description”: “A sturdy tree branch that can be used for crafting.”
“Slime Potion”: {
“ItemCategory”: “Consumable”,
“AddHealth”: 5,
“AddEnergy”: 32,
“StackSize”: 99,
“Description”: “It smells like medicine.”
“Iron Sword”: {
“ItemCategory”: “Sword”,
“ItemAttack”: 3,
“ItemSpeed”: 0.75,
“StackSize”: 1,
“Description”: “Quite a rusty sword, but should be able to get the job done.”

we have json,gd script which is autoloaded

extends Node

var item_data: Dictionary

func _ready():
item_data = LoadData (“res://Data/ItemData.json”)

func LoadData(file_path):
var json_data
var file_data =, File.READ)
json_data = JSON.parse(file_data.get_as_text())
return json_data.result

and we have which is giving me errors and wont open scenes because of that.

extends Node2D

var item_name
var item_quantity

func _ready():
#if randi() % 2 == 0:
#$TextureRect.texture = load(“res://sprites/item/Iron Sword.png”)
#$TextureRect.texture = load(“res://sprites/item/Slime Potion.png”)

var rand_val = randi() % 3
if rand_val == 0:
	item_name = "Iron Sword"
elif rand_val == 1:
	item_name = "Tree Branch"
	item_name = "Slime Potion"

$TextureRect.texture = load("res://sprites/item/" + item_name + ".png")
var stack_size = int(JsonData.item_data[item_name]["StackSize"])
item_quantity = randi() % stack_size + 1

if stack_size == 1:
	$Label.visible = false
	$label.text = String(item_quantity)

func add_item_quantity(amount_to_add):
item_quantity += amount_to_add
$Label.text = String(item_quantity)

func decrease_item_quantity(amount_to_remove):
item_quantity -= amount_to_remove
$Label.text = String(item_quantity)

so i get error and its always pointing to this line

	$label.text = String(item_quantity)

As far I can understand about this , that somehow they didnt get info from .json file .
i tiped pass in that line and scene will opens .
ofc its suppose to show 3 items which is declared in .json file and show theyr amounts , but instead it shows all 3 items but the “Iron Sword” doesnt have amount .
any ideas what causes this problem and how can i fix it?

:bust_in_silhouette: Reply From: jgodfrey



should be:


(note the capital L)

those misstakes always are the smallest .
thanks for you time man thats helped!

cenka | 2020-11-05 00:03

:bust_in_silhouette: Reply From: karmo77

hello, I have exactly the same problem on the same tutorial in the same place, I do not understand
if you find a solution could you tell me splease

hello , if you getting the same error as me you need to change in this code

if stack_size == 1:
	$Label.visible = false
	$Label.text = String(item_quantity)

to be exzact its $Label atleeast it was for me . just check if you didn put lower case L instead of capital L

cenka | 2020-11-05 16:27

Without seeing code, and the specific error, it’s hard to say what the problem is…

Unrelated, but @karmo77 - your “question” should not have been posted as an answer to @cenka’s original question. In the future, try to post something like that as 1) additional Comments, 2) post a brand new question, or 3) use the Ask a related question button.


jgodfrey | 2020-11-05 16:36