Invalid set index 'visible' (on base: 'null instance') with value of type 'bool'.

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

Hello! I’m trying to make a button that makes a Spatial node and it’s children invisible.

    onready var LL = $lightscar

func _process(delta):
	if Input.is_action_just_pressed("engine"):
		engineEnabled = !engineEnabled
		print(engineEnabled)
		if not engineEnabled:
			LL.visible = false

I keep getting Invalid set index 'visible' (on base: 'null instance') with value of type 'bool'. when I try to use it! How can I fix?

Hi.
The error means that LL is null and not an object. Therefore the problem arises from:

onready var LL = $lightscar

are you sure that $lightscar is correct?

klaas | 2021-07-07 08:12

:bust_in_silhouette: Reply From: lewis glasgow
if get_node_or_null(NodePath("lightscar")):
	$lightscar.visible = false

this checks whether the node exists but i cant see what the problem is

:bust_in_silhouette: Reply From: ebersouto008

Hello mate, I just had the same problem. The variable becomes null for some reason, so i recreated the variable for ex:

onready var LL = $lightscar

func _process():
var ll = $lightscar