# Setting text to a label causing error

**URL:** <https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068>\
**Category:** Help\
**Tags:** godot-4, gdscript, 2d\
**Created:** [December 4, 2026, 11:24am UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068 "2026-12-04T11:24:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![duckfuck](https://forum.godotengine.org/user_avatar/forum.godotengine.org/duckfuck/32/87798_2.png) [@duckfuck](https://forum.godotengine.org/u/duckfuck)\
**Post date:** [December 4, 2026, 11:24am UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/1 "2026-12-04T11:24:41Z")

</div>

### Godot Version

4.7.2 stable

### Question

Trying to update the text of a label and keep receiving this error how do i assign it to string rather than null

 ![Untitled](https://forum.godotengine.org/uploads/default/original/3X/c/5/c52bcb891dda2051a956c74960c5ee49f1e75b0f.png)

---

<div class="post-metadata">

**Author:** ![tibaverus](https://forum.godotengine.org/user_avatar/forum.godotengine.org/tibaverus/32/43649_2.png) [@tibaverus](https://forum.godotengine.org/u/tibaverus)\
**Post date:** [December 4, 2026, 11:53am UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/2 "2026-12-04T11:53:38Z")

</div>

```gd
dirt_tag.text = str("Dirt: ", Items.dirt)

```

However, make sure `dirt` is not null, it seems to be.

---

<div class="post-metadata">

**Author:** ![duckfuck](https://forum.godotengine.org/user_avatar/forum.godotengine.org/duckfuck/32/87798_2.png) [@duckfuck](https://forum.godotengine.org/u/duckfuck)\
**Post date:** [December 4, 2026, 12:06pm UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/3 "2026-12-04T12:06:41Z")

</div>

Still getting the error after trying this, Here is my item script im pulling from

 ![Untitled](https://forum.godotengine.org/uploads/default/original/3X/c/1/c1acbd33c1e5af6dd80626e633a4308aa3483380.png)

---

<div class="post-metadata">

**Author:** ![tibaverus](https://forum.godotengine.org/user_avatar/forum.godotengine.org/tibaverus/32/43649_2.png) [@tibaverus](https://forum.godotengine.org/u/tibaverus)\
**Post date:** [December 4, 2026, 12:08pm UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/4 "2026-12-04T12:08:58Z")

</div>

Where do you initialize `Items`? I can’t see it anywhere, and it doesn’t seem like `Items` is a variable in-scope.

---

<div class="post-metadata">

**Author:** ![duckfuck](https://forum.godotengine.org/user_avatar/forum.godotengine.org/duckfuck/32/87798_2.png) [@duckfuck](https://forum.godotengine.org/u/duckfuck)\
**Post date:** [December 4, 2026, 12:12pm UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/5 "2026-12-04T12:12:59Z")

</div>

The items are a global script i assumed they were initialised with that

---

<div class="post-metadata">

**Author:** ![tibaverus](https://forum.godotengine.org/user_avatar/forum.godotengine.org/tibaverus/32/43649_2.png) [@tibaverus](https://forum.godotengine.org/u/tibaverus)\
**Post date:** [December 4, 2026, 12:14pm UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/6 "2026-12-04T12:14:06Z")

</div>

I think the main problem is that you’re missing the following line from the top of the items.gd file:

```auto
class_name Items

```

It’s been a while since I used GDScript, but I believe you need to use that in order to be able to access said properties.

---

<div class="post-metadata">

**Author:** ![duckfuck](https://forum.godotengine.org/user_avatar/forum.godotengine.org/duckfuck/32/87798_2.png) [@duckfuck](https://forum.godotengine.org/u/duckfuck)\
**Post date:** [December 4, 2026, 12:18pm UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/7 "2026-12-04T12:18:21Z")

</div>

adding this breaks the global script “Class “Items” hides an autoload singleton.”

---

<div class="post-metadata">

**Author:** ![tibaverus](https://forum.godotengine.org/user_avatar/forum.godotengine.org/tibaverus/32/43649_2.png) [@tibaverus](https://forum.godotengine.org/u/tibaverus)\
**Post date:** [December 4, 2026, 12:19pm UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/8 "2026-12-04T12:19:22Z")

</div>

Could it be that you forgot to assign `dirt_tag` in the godot inspector? Since it’s an Export variable.

---

<div class="post-metadata">

**Author:** ![duckfuck](https://forum.godotengine.org/user_avatar/forum.godotengine.org/duckfuck/32/87798_2.png) [@duckfuck](https://forum.godotengine.org/u/duckfuck)\
**Post date:** [December 4, 2026, 12:20pm UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/9 "2026-12-04T12:20:11Z")

</div>

its assigned in the original image

---

<div class="post-metadata">

**Author:** ![duckfuck](https://forum.godotengine.org/user_avatar/forum.godotengine.org/duckfuck/32/87798_2.png) [@duckfuck](https://forum.godotengine.org/u/duckfuck)\
**Post date:** [December 4, 2026, 12:21pm UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/10 "2026-12-04T12:21:07Z")

</div>

the scene runs fine if im not trying to assign text to the label on ready

---

<div class="post-metadata">

**Author:** ![tibaverus](https://forum.godotengine.org/user_avatar/forum.godotengine.org/tibaverus/32/43649_2.png) [@tibaverus](https://forum.godotengine.org/u/tibaverus)\
**Post date:** [December 4, 2026, 12:24pm UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/11 "2026-12-04T12:24:43Z")

</div>

Could you put a print statement in the `_ready` function, and simply run the game? The only thing I can think of is that maybe you have this same main.gd script attached to another node that you don’t know about.

---

<div class="post-metadata">

**Author:** ![duckfuck](https://forum.godotengine.org/user_avatar/forum.godotengine.org/duckfuck/32/87798_2.png) [@duckfuck](https://forum.godotengine.org/u/duckfuck)\
**Post date:** [December 4, 2026, 12:29pm UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/12 "2026-12-04T12:29:37Z")

</div>

attempting to print in \_ready causes a crash

---

<div class="post-metadata">

**Author:** ![tibaverus](https://forum.godotengine.org/user_avatar/forum.godotengine.org/tibaverus/32/43649_2.png) [@tibaverus](https://forum.godotengine.org/u/tibaverus)\
**Post date:** [December 4, 2026, 12:30pm UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/13 "2026-12-04T12:30:20Z")

</div>

That’s not normal. So simply putting `print("something")` in ready crashes your game?

---

<div class="post-metadata">

**Author:** ![duckfuck](https://forum.godotengine.org/user_avatar/forum.godotengine.org/duckfuck/32/87798_2.png) [@duckfuck](https://forum.godotengine.org/u/duckfuck)\
**Post date:** [December 4, 2026, 12:31pm UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/14 "2026-12-04T12:31:06Z")

</div>

Oh no i meant update the text

---

<div class="post-metadata">

**Author:** ![duckfuck](https://forum.godotengine.org/user_avatar/forum.godotengine.org/duckfuck/32/87798_2.png) [@duckfuck](https://forum.godotengine.org/u/duckfuck)\
**Post date:** [December 4, 2026, 12:32pm UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/15 "2026-12-04T12:32:59Z")

</div>

Attempting to run the update\_text() function from another script also crashes the game

---

<div class="post-metadata">

**Author:** ![tibaverus](https://forum.godotengine.org/user_avatar/forum.godotengine.org/tibaverus/32/43649_2.png) [@tibaverus](https://forum.godotengine.org/u/tibaverus)\
**Post date:** [December 4, 2026, 12:33pm UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/16 "2026-12-04T12:33:52Z")

</div>

For now, simply remove `update_text()` from your ready function, and simply put this there:

```auto
func _ready() -> void:
	print("test")

```

Then run your game. Does “test” only get printed once, or multiple times?

---

<div class="post-metadata">

**Author:** ![duckfuck](https://forum.godotengine.org/user_avatar/forum.godotengine.org/duckfuck/32/87798_2.png) [@duckfuck](https://forum.godotengine.org/u/duckfuck)\
**Post date:** [December 4, 2026, 12:34pm UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/17 "2026-12-04T12:34:39Z")

</div>

it gets printed twice

---

<div class="post-metadata">

**Author:** ![tibaverus](https://forum.godotengine.org/user_avatar/forum.godotengine.org/tibaverus/32/43649_2.png) [@tibaverus](https://forum.godotengine.org/u/tibaverus)\
**Post date:** [December 4, 2026, 12:35pm UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/18 "2026-12-04T12:35:16Z")

</div>

That means you have another Node which has this same main.gd script attached to it. You need to either remove that, or if it’s intentional, that second node probably doesn’t have the label properly set in the inspector.

---

<div class="post-metadata">

**Author:** ![duckfuck](https://forum.godotengine.org/user_avatar/forum.godotengine.org/duckfuck/32/87798_2.png) [@duckfuck](https://forum.godotengine.org/u/duckfuck)\
**Post date:** [December 4, 2026, 12:36pm UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/19 "2026-12-04T12:36:29Z")

</div>

only my main node has the script attached

---

<div class="post-metadata">

**Author:** ![tibaverus](https://forum.godotengine.org/user_avatar/forum.godotengine.org/tibaverus/32/43649_2.png) [@tibaverus](https://forum.godotengine.org/u/tibaverus)\
**Post date:** [December 4, 2026, 12:37pm UTC](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068/20 "2026-12-04T12:37:38Z")

</div>

If “test” gets printed twice, then you have another node which has the script attached to it. While your game is running, go back to Godot and on the left side, click on “Remote”, that will show your full scene tree while your game is running, so you can check what nodes actually exist during runtime. Chances are you have two main.gd nodes somewhere.

[Next page](https://forum.godotengine.org/t/setting-text-to-a-label-causing-error/148068.md?page=2)
