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
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)