Error when trying to disable a button

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

Hi, i’m new to Godot
This is my first Godot project. Its for my school project
I working on a farming game
What i want to do here is disabling a button if the coin variable is less than 25. The concept of that looks like this: You don’t have enough money = you can’t buy the item
Here is the code:

extends Node

func _process(delta):
  If Global.coin < 25:
    $parent/BuyButton.disabled = true

But, when i run the game, and click a button that decrease coin variable until the coin value is below 25, its shows an error message: Invalid set index ‘disabled’ (on base: ‘null instance’) with value of type ‘bool’.
How do i fix that?

P.S: Sorry if my question looks un-specific(or have bad grammar)

:bust_in_silhouette: Reply From: Picster

The message says that the node you are trying to get via $parent/BuyButton was not “found”.

if you try to get the parent node, it would be get_parent().get_node("BuyButton").disabled = true

Im just going to try it without the getting the parent:

extends Node

func _process(delta):
  if Global.coin < 25:
    get_node("BuyButton").disabled = true

and still the same error

Tim Log | 2022-11-10 13:15