I am trying to make a double click "m" to return to menu script. But I have no clue how, can anyone help?
Double click <key> to return to menu. How?
1 answer
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
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