Hello guys!
I was working on a menu and I wanned to make that the menu opens if you click the button ‘M’ twice (In like a second or something) and I have no idea where to start.
Can anyone help me?
For these instances, the client needs to record the exact time the last input of M is pressed. And for each time the input is fired, subtract the last input time with the previous input time. If the result yields in less than a few hundreds milliseconds, then proceed with opening the menu(displaying it).
local UserInputService = game:GetService("UserInputService")
local BUTTON_TO_PRESS = Enum.KeyCode.M
local LastPressed = nil
UserInputService.InputBegan:Connect(function(Key,FocusedGUI)
if FocusedGUI then return end
if Key.KeyCode == BUTTON_TO_PRESS then
if LastPressed and tick() - LastPressed <= 0.3 then
--Code to open menu
end
LastPressed = tick()
end
end)
You can edit the 0.3 value to how fast you want them to press the button
Thanks mate, I’ll try to test it out later.