How would I be able to detect the E Key held down for x amount of time?

Hi, So I am working on a new game where I want to allow the player to hold down the E key for an X amount of time and Hack things. I see in games such as Jailbreak, Mad City, and Emergency Response: Liberty County has these systems where while you hold down E the GUI then progresses throughout how much time is left. I want to implement this into my game. I know how to detect if someone pressed E but I do not know how to detect how long someone has pressed it for and then to continue its functions once reaching the points where it can do that. Please help me understand a solution to this and how I can accomplish this.
Thanks in advance,
b_irdio

5 Likes

connect to UserInputService.InputBegan and UserInputService.InputEnded, check for Enum.KeyCode.E on both and get the time difference between both events. If the time difference is >= the time required, then it was held down long enough.

1 Like

Use forum search before posting to make sure your question hasn’t been answered before:

8 Likes
1 Like