Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can a double tap be detected?

Asked by 8 years ago

I've tried multiple scenarios. What I am trying to do is allow a basic function to fire when You double tap "A", but I can't seem to do it. I assume the problem is that input2 is already being set as "A" when I first press it because pressing it for the second time in the game means that every time you press it hence it will fire the function.

01bool = true
02locplay = game.Players.LocalPlayer
03human = locplay.Character.Humanoid
04game:GetService("UserInputService").InputBegan:connect(function(input1)
05    if input1.KeyCode == Enum.KeyCode.A then
06    local bool = false
07        wait(.02)
08        if bool == false then
09            game:GetService("UserInputService").InputBegan:connect(function(input2)
10                if input2.KeyCode == Enum.KeyCode.A then
11                local bool = true
12                    if bool == true then
13                        human.WalkSpeed = 50
14                        wait(.25)
15                        human.WalkSpeed = 16
View all 22 lines...

1 answer

Log in to vote
1
Answered by
shayner32 478 Trusted Moderation Voter
8 years ago

Try this code out:

01click = false
02locplay = game.Players.LocalPlayer
03human = locplay.Character.Humanoid
04game:GetService("UserInputService").InputBegan:connect(function(input1)
05    if input1.KeyCode == Enum.KeyCode.A then
06        if click then
07            print("A was double tapped")
08            return
09        end
10        click = true
11        wait(0.4)
12        click = false
13    end
14end)
Ad

Answer this question