Index p_bus = -1 is out of bounds

Godot 4.2.1

I’m trying to make a volume settings menu, but the sliders aren’t working. The game gives me these errors:

E 0:00:00:0675 @ setSliderValue(): Index p_bus = -1 is out of bounds (buses.size() = 3).
  <C++ Source>   servers/audio_server.cpp:924 @ get_bus_volume_db()
  <Stack Trace> @ setSliderValue()
        @ _ready()

E 0:00:00:0675 @ onValueChanged(): Index p_bus = -1 is out of bounds (buses.size() = 3).
  <C++ Source>   servers/audio_server.cpp:916 @ set_bus_volume_db()
  <Stack Trace> @ onValueChanged()
        @ setSliderValue()
        @ _ready()

Here is my code:

extends Control

@onready var h_slider = $HBoxContainer/HSlider
@onready var label = $HBoxContainer/Label

@export_enum("Master", "Music", "Sfx") var busName: String

var busIndex: int = 0

func _ready():
func setAudioNumText():
	label.text = str(h_slider.value * 100)

func getBusNameByIndex():
	busIndex = AudioServer.get_bus_index(busName)

func setSliderValue():
	h_slider.value = db_to_linear(AudioServer.get_bus_volume_db(busIndex))

func onValueChanged(value: float):
	AudioServer.set_bus_volume_db(busIndex, linear_to_db(value))

I’m sorry I’m not able to give a more detailed description of my problem, but I didn’t find anyone with a similar problem and I have no clue where to even start solving this issue. I re-watched the tutorial I was watching several times but couldn’t figure out what I did wrong.
Thanks to anyone who can help me figure this out. :slight_smile:

You probably have forgotten to provide a value to your export variable busName. Since you don’t provide a default value, it will be undefined when looking up the busIndex, thus get_bus_index (correctly) returns -1.

That was it, thanks :slight_smile: