So, I am making this simple slash and hit weapon stick that has sound effects when you hit a humanoid (Except Player).
My problem is when it is already hitting a humanoid model, the touch event fires multiple at the same time.
I know how debounce works but the “Thud” sound should be only possible if the hitting animation is at the slashing animation.
Is there a way to limit to 1 hit only per slash?
Here’s my code:
local AnimationTrack
Tool.Activated:Connect(function()
if Humanoid and Humanoid.Health > 0 then
if AnimationTrack == nil then
local Animator = Humanoid.Animator
local Animation= Instance.new("Animation")
Animation.AnimationId = "rbxassetid://" .. Animations.Slash_1
AnimationTrack = Animator:LoadAnimation(Animation)
AnimationTrack:Play()
Slashing = true
-- Slash
local Slash = SFX.Slash[math.random(#SFX.Slash)]
Slash:Play()
local HitDebounce = false
Handle.Touched:Connect(function(hit)
local isUser = Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") and isUser ~= LocalPlayer then
if Slashing == true and HitDebounce == false then
HitDebounce = true
local HitThud = SFX.Thuds[math.random(#SFX.Thuds)]
HitThud:Play()
HitDebounce = false
HitThud.Ended:Wait()
end
end
end)
Trail.Enabled = true
AnimationTrack.Stopped:Connect(function()
Trail.Enabled = false
Slashing = false
task.wait(.25)
AnimationTrack = nil
end)
end
end
end)