✓ Accepted answer
Check this out for the info on Keyboard input: http://wiki.roblox.com/index.php?title=Keyboard_input
As for the pausing and unpausing, I can't be very much help. But I can show you how to fire a function when a key is being held, and get the wait time.
Here is the basic structure for getting the keyboard input:
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.R then
print("Player pressed R")
end
end
function onKeyOff(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.R then
print("Player stopped pressing R")
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
game:GetService("UserInputService").InputEnded:connect(onKeyOff)
As for finding how long a player has pressed R, or whatever key you want, you can simply put a loop in the function that fires when R has been pressed (onKeyPress), and in that loop you can count each second that has passed. When the key has stopped being pressed, the function that fires when R has stopped being pressed will make the loop stop.
Here's the visual:
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.R then
print("Player pressed R")
Pressing = true
Counter = 0
if Pressing then
wait(1)
Counter = Counter + 1
end
end
end
function onKeyOff(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.R then
print("Player stopped pressing R")
Pressing = false
print(Counter)
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
game:GetService("UserInputService").InputEnded:connect(onKeyOff)
The Counter variable can only count every second. If you want to count in fractions of a second, then simply lower the wait(1) and Counter + 1 accordingly.