Enemy has just been damaged, Sound bugs out

I use visual code. I have been having issues with a condition of health has just been damaged on player. When the player damaged it should play a sound. But the sound bugs out on the first time the player is damaged. Its fine after the first hit. I was wondering how to fix this issue.

it seems the bug is just when the first sound is played it bugs out.

Is that from using copy within gdevelop? Can you post a screenshot of the applicable events.

What do you mean by bugs out? Sounds need to be preloaded either using an action or ticking the checkbox on the resources screen.

I agree with @Keith_1357 - screen snip the events, don’t copy and paste the events. What you’ve pasted isn’t Javascript - it’s a partial JSON extract.

Trying to read the JSON, it looks like your issue will be that the Health::IsJustDamaged is causing the sound to be played repeatedly. I don’t think the function changes to false until the health has been modified again.

A solution, but one that won’t work a fair bit of the time, is to add a “Trigger Once” condition when you check if health has just been damaged.

A better solution is to play the sound in the event that inflicts the damage. Then it’s played once at the right time. You may have to use the play sound action in a few places, but it’ll stop the current sound issue.

I have changed it so you can see the visual code.

Is the sound being preloaded?

I prefer the play sound on channel. It gives you more options like playing each sound type on a different channel. It also has a sound is stopped condition so you can check if a sound is playing before trying to play it again.

Add trigger once under health been just damaged

Seeing the events, the issue will be a continual collision between player and enemy, which will also be draining the player’s health.

Either put a trigger once condition on the second event (the one that checks for collision between player and enemy), or add an action to that event to move player away from enemy (or vice versa).

I have found the fix to this bug. [Rasterisko] gave me the solution. Make sure to play the sound once using Trigger once.