I am trying to make a double click "m" to return to menu script. But I have no clue how, can anyone help?
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.
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?