I’m doing an animation system, but my Debounce isn’t working, and every time the Player presses a key it goes twice
Mouse.KeyDown:Connect(function(key)
local KeyFind = Keys[key]
local Health = Humanoid.Health
if KeyFind and InAnimation == false and Health > 0.30 and not Character:FindFirstChild("Caixa") and not Debounce then
InAnimation = true
Debounce = true
print(InAnimation,Debounce)
if KeyFind[2] == false and State == "parado" then
controls:Disable()
CanRun.Value = false
elseif KeyFind[2] == false and State ~= "parado" then
print("Setado01")
InAnimation = false
Debounce = false
return
end
if key == "q" then
local RandomAnim = math.random(#KeyFind[1])
AnimTrack = KeyFind[1][RandomAnim]
else
AnimTrack = KeyFind[1]
end
if key == "q" or key == "t" then
local touch
local function onTouch(hit)
if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
if hit.Parent.Humanoid.Health > 0 then
local targetCharacter = hit.Parent
RemoteEvent:FireServer({
N0 = "Soco",
N1 = targetCharacter.Humanoid,
N2 = script.Punch,
})
RemoteEvent:FireServer({
N0 = "InCombateSoco"
})
touch:Disconnect()
end
end
end
AnimTrack:Play()
if key == "q" then
touch = LocalPlayer.Character["RightHand"].Touched:Connect(onTouch)
elseif key == "t" then
touch = LocalPlayer.Character["RightFoot"].Touched:Connect(onTouch)
end
AnimTrack.Stopped:Wait()
touch:Disconnect()
wait(1)
print("Setado02")
InAnimation = false
Debounce = false
elseif key ~= "q" and key ~= "t" then
AnimTrack:Play()
print("Played02")
end -- Soco e Chute
elseif KeyFind and InAnimation == true and Health > 0.3 then --and State == "parado"
local AnimTrack = KeyFind[1]
if AnimTrack.IsPlaying == true then
if KeyFind[2] == false then
controls:Enable()
if not Character:FindFirstChild("Caixa") then
CanRun.Value = true
Humanoid.WalkSpeed = game.StarterPlayer.CharacterWalkSpeed
Humanoid.JumpHeight = game.StarterPlayer.CharacterJumpHeight
end
end
AnimTrack:Stop()
print("Setado03")
InAnimation = false
Debounce = false
end
end
end)