Audio keeps repeating

This may sound confusing, in fact, it is. But i’ll try to explain as much as i can.

Audio keeps Repeating

So basically i’m doing a script that everytime a player hits another player with a tool it plays an audio, but that audio keeps repeating.

Detailed Explanation

Basically, i have a tool wich when it is activated it reproduces an animation and makes it so if another player hits the tool, a sound is played, and when that sound keeps repeating over and over, because the player gets hitted a lot of consecutive times, and that’s what i need help with.

I need help to make it so the audio only reproduces once per swing, wich means only once at each animation. Here’s a video showing in details.

Please don’t question my animating skills

robloxapp-20201114-1548469.wmv (224.2 KB)
If the video crashes and doesn’t move, imagine that i am hitting the dummies with a bat and that’s the noise it’s making

Script

Here’s the most important parts of the script

I can give more information if needed, and i would greatly appreciate if someone could help me.

Thanks! :slightly_smiling_face:

Can you fix the video? I can’t even see anything.

Characters have a lot of parts like legs and arms, when you hit something, you may touch not only one joint, but a lot of them if not all. To prevent that, you can add a debounce like this:

local debounce = false

script.Parent.Handle.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local plr = hit.Parent
        if plr.Name ~= actualplayer.Name and not debounce then
            debounce = true

            local particle = script.Parent.Particle:Clone()
            script.Parent.Bonk:Play()

            wait(0.5)
            debounce = false
        end
    end
end)

Also, use debounce for this. I still don’t understand debounce myself but I believe it stops things from repeating multiple times.

It did stop in the video, so no.

1 Like

I can try, but i’ll see about that

It is not looped, the reason it keeps repeating is because

1 Like

Then go ahead and use your newfound knowledge to make your game better!

1 Like

Ohh, is that actually how it works? Sorry, didn’t know myself, haha. Guess I have used it before then.

Did it work or is something wrong?

It didn’t work, i don’t know if i did something wrong of it didn’t actually work

1 Like

Make a blacklist table, use the character’s and the gun’s descendants

then have a line something like:

        if blacklistTable[v] then return end

Maybe not the best way to do it but should stop it from triggering because of it’s own parts

Aren’t you going to mark the solution?

1 Like