Cant get audio working

Godot Version

4.3

Question

Cant get audio working

extends Button

func _ready():
var __sound_1 = AudioStreamPlayer.new()
__sound_1.name = ‘Bruh - Sound Effect (HD).mp3’
__sound_1.set_stream(load(‘Bruh - Sound Effect (HD).mp3’))
add_child(__sound_1)

func _on_pressed():
var __sound_node_1 = get_node(‘Bruh - Sound Effect (HD).mp3’)
__sound_node_1.volume_db == 50
__sound_node_1.pitch_scale = 1
__sound_node_1.play()

The problem here is the name you’re using for the node that contain invalid characters (the “.”) that will be replaced for a “_” (see the docs: Node — Godot Engine (stable) documentation in English)


extends Button

func _ready():
	var __sound_1 = AudioStreamPlayer.new()

	# Use a simpler name instead
	__sound_1.name = ‘sound_1’

	__sound_1.set_stream(load(‘Bruh - Sound Effect (HD).mp3’))
	add_child(__sound_1)

func _on_pressed():
	var __sound_node_1 = get_node(‘sound_1’)

	# This line is doing nothing, you're comparing values instead attributing,
	# also 50 db will make the sound very high compared to the others
	__sound_node_1.volume_db == 50

	__sound_node_1.pitch_scale = 1
	__sound_node_1.play()
1 Like

Thank you

If that worked you can mark the question as solved