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

Make something happen after double tapping a key?

Asked by 6 years ago

This is what I have so far in my quest in trying to make this work, all of this part is done in a local script that is inside the player's character.

local flipping = false
local player = game.Players.LocalPlayer
local character = player.Character
local hum = character:FindFirstChild("Humanoid")
local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(input, event)
    if event then return end
    if input.KeyCode == Enum.KeyCode.Q then
        if not flipping then
            flipping = tick()
        else
            if tick() - flipping < 0.2 then
                flipping = true

                --Do Stuff here             

                wait(1)
                flipping = false        
            else
                flipping = false
            end
        end
    end 
end)

I keep getting this error which I don't know if this is contributing to it not working that well, and I don't really understand how I would fix it.

Workspace.MyTradeJustWentViral.StaminaMoves:87: attempt to perform arithmetic on upvalue 'flipping' (a boolean value)

It's not really that accurate at detecting if you actually double tapped the button. Any help on this would be appreciated.

2 answers

Log in to vote
2
Answered by 6 years ago

Hi MyTradeJustWentViral,

I will just show you how to double tap simply. I don't know what the above answer is trying to do but, it seems very inefficient. It's not that hard to make a double tap.

Script

----------------- Services ----------------------
local players = game:GetService("Players");
local uis = game:GetService("UserInputService");
----------------- Services ----------------------

----------------- Initial Variables ----------------------
local player = players.LocalPlayer;
local t = 0; -- Start at 0, this will be what records the previous tick.
local dif = tick() - t; -- The difference between each click.
----------------- Initial Variables ----------------------

function do_it(key, gp) 
    if key.KeyCode == Enum.KeyCode.Q and not gp then   -- Checks if Q was pressed and if the player meant to press it, as in was it pressed while typing or was it just pressed with intention(without typing)
        dif = tick() - t; -- Updates the difference.

        if dif < 3 then  -- Checks if the difference is less than 3 seconds, so, you need to click a second time within the range of 3 seconds to activate double tap.
            print("You double tapped."); -- Prints this if you did double tap.
            t = 0; -- Sets the previous tick to 0 because we're starting a new sequence.
            return -- returns so that the rest of the function doesn't run, so that the t doesn't become tick() again because we're starting a new sequence.
        end -- end for if statement to check if the difference is smaller than 3.

        t = tick(); -- Updates the previous tick with a new tick since the new tick becomes the previous tick.
    end -- end for if statement to check if Q was pressed and if it was meant to be pressed.
end -- end for function.

uis.InputBegan:Connect(do_it); -- Connects function to event.

Well, I hope I helped and have a wonderful day/night.

Thanks,

Best regards,

~~ KingLoneCat

0
Worked, thats a lot! MyTradeJustWentViral 5 — 6y
0
No problem. KingLoneCat 2642 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
local x = Instance.new("BoolValue")
x.Parent = script
x.Name = "BoolValue"

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.Q then
    script.BoolValue.Value = true
        game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent)
        if script.BoolValue.Value == true then
                if inputObject.KeyCode == Enum.KeyCode.Q then

                    --stuffs here

                    script:Destroy()
                end
            script.BoolValue.Value =  false
        end
        end)
    end 
end)

script is temporary, after detecting 1 double click it will destroy, sorry i can't make any script that will detect double taps, But that's what i did so far

Answer this question