I am reworking my combat system but the animations can be replayed if you spam Q. I don’t know what is causing this and I have tried to implement a debounce however, I am unsuccessful.
UIS.InputBegan:Connect(function(input, Processed)
if Processed then return end
if input.KeyCode == Enum.KeyCode.Q and ran == 1 and Debounce == false then
Animations['LeftPunch']:Play()
wait(0.5)
ran = 2
Debounce = true
elseif ran == 2 and Debounce == true then
Animations['RightPunch']:Play()
wait(0.5)
ran = 1
Debounce = false
end
end)
if Processed then return end
if input.KeyCode == Enum.KeyCode.Q and ran == 1 and Debounce == false then
Animations['LeftPunch']:Play()
wait(0.5)
ran = 2
Debounce = true
elseif ran == 2 then
Animations['RightPunch']:Play()
wait(0.5)
ran = 1
Debounce = false
end
end)
The reason that you can spam the animation is because of what order you set your debounces in. In order to make sure that you are not able to spam the animation, you need to set the debounces first, so that if they press Q again, it will check for the debounce first instead of playing the animation then checking the debounces.
New Code:
UIS.InputBegan:Connect(function(input, Processed)
if Processed then return end
if input.KeyCode == Enum.KeyCode.Q and ran == 1 and Debounce == false then
ran = 2
Debounce = true
wait(0.5)
Animations['LeftPunch']:Play()
elseif ran == 2 and Debounce == true then
ran = 1
Debounce = false
wait(0.5)
Animations['RightPunch']:Play()
end
end)
UIS.InputBegan:Connect(function(input, Processed)
if not Debounce then
Debounce == true
(your code)
wait(How many sec you want)
Debounce = false
end
end)