How to change the value of a slider via script (SOLVED)

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

I’m trying to change the value of a slider when the scene starts from Data saved.

Here’s the code :

extends Control

onready var musicslider = $MenuContainer/MusicContainer/MusicSlider

func _ready():
    musicslider.value = -14

Error that I get :

Invalid set index ‘value’ (on base: ‘Nil’) with value of type ‘float’.

Thanks for the help in advance

SOLVED : My reference was wrong as poined below, I needed to do this : onready var musicslider: Slider = get_node("MenuContainer/MusicContainer/MusicSlider")

:bust_in_silhouette: Reply From: jgodfrey

The value property is correct for changing the slider. Though, you don’t have a valid reference to the slider itself (hence the (on base: 'Nil') portion of the message. I can’t say what’s wrong with your reference without knowing what your scene tree looks like, but it’s wrong.

enter image description here

Here’s my nodes for that scene.

Loxyrak | 2020-08-12 20:28