# How can i play a sound when a key is pressed?

**URL:** <https://forum.godotengine.org/t/how-can-i-play-a-sound-when-a-key-is-pressed/9682>\
**Category:** Archive\
**Created:** [August 20, 2021, 4:08pm UTC](https://forum.godotengine.org/t/how-can-i-play-a-sound-when-a-key-is-pressed/9682 "2021-08-20T16:08:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://forum.godotengine.org/uploads/default/original/2X/4/4b0a7fa8a6334634b94a13d421f0d99e6f04e21f.svg) [@system](https://forum.godotengine.org/u/system)\
**Post date:** [August 20, 2021, 4:08pm UTC](https://forum.godotengine.org/t/how-can-i-play-a-sound-when-a-key-is-pressed/9682/1 "2021-08-20T16:08:53Z")

</div>

| | | |
| --- | --- | --- |
| ℹ | **Attention** | Topic was automatically imported from the old Question2Answer platform. |
| 👤 | **Asked&nbsp;By** | Frostcatzz |

**This is my Code:**

```auto
var speler = AudioStreamPlayer.new();

var first_time = true
var is_playing = false
func _physics_process(delta):
	if Input.is_action_just_pressed("primary_fire"):
		if first_time:
			self.add_child(speler);
			speler.stream = load("res://Sounds/GunShot.wav");
			first_time = false
		if not is_playing:
			speler.play(true);
			is_playing = true

```

Is something wrong? when i press the key its doesnt play a sound  
The key input for “primary\_fire” = Left Click

Pls help me

---

<div class="post-metadata">

**Author:** ![system](https://forum.godotengine.org/uploads/default/original/2X/4/4b0a7fa8a6334634b94a13d421f0d99e6f04e21f.svg) [@system](https://forum.godotengine.org/u/system)\
**Post date:** [August 20, 2021, 6:46pm UTC](https://forum.godotengine.org/t/how-can-i-play-a-sound-when-a-key-is-pressed/9682/2 "2021-08-20T18:46:02Z")

</div>

| | | |
| --- | --- | --- |
| 👤 | **Reply From:** | estebanmolca |

I just tested your script and it works, check the file name well or try another, the folder is Sounds, sounds, sound !? My version is v3.3.2.stable.oficial
