Sure, it really depends. I don’t think there is anything wrong with your approach. What ever method, your mission is to not play it every frame.
Let’s say this is a treasure chest and you want to transition to an open state. Once open some process is done. “variable” is your open state.
With a state machine you can define a closed and open state. When an action to open happens you would play the sound and transition to open state. I would tuck the play sound into the animation or the action sensor to transition.
This situation can usually be solved with a finite state machine. And there are multiple forms of it. Godot has a built in state machine hidden in the AnimationTree node.
Here is a video i like showing how to use it.