I figured what the problem is and it has to do with this bit of code in the coin script:
func _on_Area2D_body_entered(body):
print(body.name)
a.play()
scene_instance.sc+=10
queue_free()
pass # Replace with function body.
When you enter the area it starts to play the sound but immediately after you kill the coin node using queue_free()
. So, the sound isn't played at all. You will notice that if you remove this line, the coin will not disappear and the sound will play normally.
I suggest you place the sound somewhere else in your game, so that it is independent from other elements that might get destroyed in-game. Make a separate script, or put it your scene_instance
singleton.
As for the looping sound, that's an import property. Go to your sound file in the coin folder, select it and go to the Import tab (upper left corner of the editor, Godot 3.1 default layout). There you will see the Loop property ticked. Uncheck it and hit reimport. Problem solved!
Please upvote this answer and mark it as best if you found it useful, so that others can find it too.