I am attempting to make a basketball dribbling system, and would like to make it so that if you press Z once, it will do a Crossover however if you double tap Z, it will do a Sidestep.
I currently have this script:
local DRIBBLE_COMBOS = {
["Threshold"] = 0.25,
["LastZPress"] = 0,
["ZPressed"] = false,
}
UIS.InputBegan:Connect(function(input, gp)
if (input.KeyCode == Enum.KeyCode.Z) then
local currentTime = tick()
local function SinglePress()
task.wait(DRIBBLE_COMBOS.Threshold)
if (DRIBBLE_COMBOS.ZPressed) and not (DRIBBLE_COMBOS.DoubleTapped) then
print("Crossover")
DRIBBLE_COMBOS.ZPressed = false
end
end
local function DoubleTap()
DRIBBLE_COMBOS.ZPressed = false
print("Sidestep")
end
if not DRIBBLE_COMBOS.ZPressed then
DRIBBLE_COMBOS.ZPressed = true
SinglePress()
end
if (currentTime - DRIBBLE_COMBOS.LastZPress) <= DRIBBLE_COMBOS.Threshold then
DoubleTap()
end
DRIBBLE_COMBOS.LastZPress = currentTime
end
end)
The issue is that it does detect double presses but also single presses. So the output looks like this when I double tap Z:
Crossover
Sidestep
If I double tap Z, it should only output Sidestep. Does anyone know how I can overcome this challenge? Thanks! 