Creating Inventory System get issue 'invalid access to key property or texture

Godot Version

Godot 4

Question

Hi there - I think I made a mistake somewhere. I am trying to follow a video by DevWorm to write code for a game I am trying to develop. The code is for an inventory system that updates the UI slots as you collect an item.

I keep getting the error "Invalid access to key property or texture on a base object of type ‘Nil’.

I have rewatched the videos loads of times and the code is similar / the same with my own variables in places. I am feeling a little confused. Please help!

It tells me the error are in these two scripts:

extends Panel

@onready var item_visual: Sprite2D = $CenterContainer/Panel/item_display
@onready var amount_text: Label = $CenterContainer/Panel/Label

func update(slot: InvSlot):
	if !slot:
		item_visual.visible = false
		amount_text.visible = false
	else:
		item_visual.visible = true
		item_visual.texture = slot.item.texture
		amount_text.visible = true
		amount_text.text = str(slot.amount)

^^^ Line 12

extends Control

@onready var inv: Inv = preload("res://inventory/playerinv.tres")
@onready var slots: Array = $NinePatchRect/GridContainer.get_children()

var is_open = false

func _ready():
	inv.update.connect(update_slots)
	update_slots()
	close()
	

func update_slots():
	for i in range(min(inv.slots.size(), slots.size())):
		slots[i].update(inv.slots[i])



func _process(delta):
	if Input.is_action_just_pressed("e"):
		if is_open:
			close()
		else:
			open()

func open():
	visible = true
	is_open = true

func close():
	visible = false
	is_open = false

^^^ Lines 10 and 16

Any help would be beautiful, I am trying to get basic functions in the game so that I can start adding the actual content and story / mechanics.

Thanks!

1° Format your code correctly, its hard to read as is, select all the code and press this button:

image

2° Points which line is throwing the error
3° Show a print of your scene to help indentify wrong node paths

Hi - thanks I didnt know we could do that!

I specified the lines that threw errors below each code section :smiley:

I will take a screenshot when home, thanks!