Hello, Im making a fighting game where the player clicks either LeftClick or RightClick to create an animation where the player punches. Hit detection is all set and so are the animations.
I want to be able to make it so the player can click numerous times without having a timeout. Currently, there’s a debounce in the user input so that when a player clicks while the player is in a fighting animation nothing happens. I have this debounce because if the player spam clicks the animation repeats over and over without letting it finish. However, I have combos in the game and having this debounce makes it unappealing. I want it to make it so when the player clicks two times in rapid succession, the character successfully does two punching animations one after another
Player clicks left click two times
Player left punch
Player left punch
This is my code from the local script
local UserInputService = game:GetService("UserInputService")
local event = ReplicatedStorage.Events.Input
local character = game.Players.LocalPlayer.Character
local LeftHand = character.LeftHand
local RightHand = character.RightHand
local Hit = ReplicatedStorage:WaitForChild("Events").Hit
character.Values.Fighting.Value = false
local debounce = false
local debounce2 = false
local hand
local inputs = {}
local combo = false
local function checkCombo()
if #inputs >= 3 then
if inputs[#inputs - 2] == Enum.UserInputType.MouseButton1 then
if inputs[#inputs - 1] == Enum.UserInputType.MouseButton2 then
if inputs[#inputs] == Enum.UserInputType.MouseButton1 then
combo = true
print("combo")
table.clear(inputs)
end
end
end
if inputs[#inputs - 2] == Enum.UserInputType.MouseButton2 then
if inputs[#inputs - 1] == Enum.UserInputType.MouseButton1 then
if inputs[#inputs] == Enum.UserInputType.MouseButton2 then
combo = true
print("combo")
table.clear(inputs)
end
end
end
end
end
local function UserInput(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if character.Values.Fighting.Value == false then
table.insert(inputs, input.UserInputType)
checkCombo()
print(inputs)
if combo == true then
event:FireServer(character, "UpperCut")
hand = "left"
else
event:FireServer(character, "LeftPunch")
hand = "left"
end
combo = false
end
end
if input.UserInputType == Enum.UserInputType.MouseButton2 then
if character.Values.Fighting.Value == false then
table.insert(inputs, input.UserInputType)
checkCombo()
print(inputs)
if combo == true then
event:FireServer(character, "Haymaker")
hand = "right"
else
event:FireServer(character, "RightPunch")
hand = "right"
end
combo = false
end
end
end
UserInputService.InputBegan:Connect(UserInput)
LeftHand.Touched:Connect(function(part)
if part.Parent:FindFirstChild("Humanoid") and not (part.Parent == character) and debounce == false and hand == "left" then
debounce = true
print("target found")
local victim = part.Parent
Hit:FireServer(character, victim)
character.Values.Fighting.Changed:Wait()
hand = nil
debounce = false
end
end)
RightHand.Touched:Connect(function(part)
if part.Parent:FindFirstChild("Humanoid") and not (part.Parent == character) and debounce == false and hand == "right" then
debounce = true
print("target found")
local victim = part.Parent
Hit:FireServer(character, victim)
character.Values.Fighting.Changed:Wait()
hand = nil
debounce = false
end
end)