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

Double click <key> to return to menu. How? [closed]

Asked by 4 years ago

I am trying to make a double click "m" to return to menu script. But I have no clue how, can anyone help?

0
Well, the best way to do it is to put something inside of the button press that goes along the lines of if ___ == false then ___ == true ..... if ___ == true then ______ - Your code. If you wanna know how to do a on button press, you should probably use UserInputService fighterkirbyzx 102 — 4y

Closed as Not Constructive by JakyeRU and hiimgoodpack

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
amanda 1059 Moderation Voter
4 years ago
Edited 4 years ago

Before you get into more advanced input detection, focus on just a single key tap.

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(inputObject, gameEvent)
    if inputObject.KeyCode == Enum.KeyCode.M and not gameEvent then
        --make menu gui visible/not visible
    end
end)

It is widely only considered a double tap if the second tap is immediately after the first. Here is a method of performing this.

Decide on a time window for the second tap to be performed: .3 seconds is a reasonable amount of time to double tap, adjust if needed.

Use tick() to get the current timestamp in seconds on the first tap.

Now every time you tap M, it checks to see if .3 seconds have elapsed since the last time you tapped M. If not, then it is a double tap and you can toggle the menu where the comment is.

local UIS = game:GetService("UserInputService")

local firstTap = tick() --initializing

UIS.InputBegan:Connect(function(inputObject, gameEvent)
    if inputObject.KeyCode == Enum.KeyCode.M and not gameEvent then
        if tick() - firstTap <= .3 then
            print("Double tap")
            --make menu gui visible/not visible
        else
            print("Single tap")
            firstTap = tick()
        end
    end
end)

This code has been tested in Studio. I recommend changing any variable names so that they make the most sense to you.

Let me know if you have questions.

Ad