Hi, I have been getting good with UserInputService on roblox. I want to know how to check if a player has pressed a key 2 times. Should I use some value and use if statements or is there an feature for it?
That's really easy
local KeyPressed = 0 --Put UserInputService here --Put Key Input Function here KeyPressed = KeyPressed + 1 if KeyPressed >= 2 then print("The Player has pressed the key more than 2 times") end
-- LocalScript in StarterCharacterScripts or some other Local location local inputService = game:GetService('UserInputService') local keys = { } inputService.InputBegan:Connect(function(input) -- turn the Enum into a string local str = tostring(input.KeyCode) -- is it in our table yet? Did we press that key yet? local index = keys[str] if index then -- if we pressed it twice if index >= 2 then print(string.format("%s has been pressed %s times!",str,index)) end else -- else if it's not set, then se that key press to 1 keys[str] = 1 end -- inc up by one on each press keys[str] = keys[str] + 1 end)