Hi, I am making a game and I want the player to click “M” twice to be sent back to the menu. I do not tend to use UserInputService so I don’t really know what to do.
I have this and I think it is the start of the script
(This is in starterPlayerScripts)
local uIS = game:GetService("UserInputService")
uIS.InputBegan:Connect(function(input)
end)
local player = game.Players.LocalPlayer
local userInputService = game:GetService("UserInputService")
local lastKeyPressTime = 0
local doubleClickThreshold = 0.5 -- Adjust the threshold as needed
local function onKeyPress(input, gameProcessedEvent)
if gameProcessedEvent then
return
end
if input.KeyCode == Enum.KeyCode.M then
local currentTime = tick()
if (currentTime - lastKeyPressTime) <= doubleClickThreshold then
-- Double-click action here
print("M key double-clicked!")
end
lastKeyPressTime = currentTime
end
end
userInputService.InputBegan:Connect(onKeyPress)