I wanna know how to detect the user/player is holding down a certain key for let’s say 5 seconds. Thanks!
also should it be in a server or local script? Thanks again!
It should be local script because key detection is mainly used locally.
You could try something like this
01 | local UIS = game:GetService( "UserInputService" ) |
02 | UIS.InputBegan:connect( function (keycode) |
03 |
04 | if keycode.keyCode = = Enum.KeyCode.w then -- Change w to the key you want |
05 | local keydown = 0 |
06 | for rounds = 1 ,( 5 * 4 ) do --change 5 to the amount of seconds you want |
07 | wait( 0.25 ) |
08 | if keycode.keyCode = = Enum.KeyCode.w then -- Change w to the key you want |
09 | keydown = keydown + 1 |
10 | end |
11 | if keydown ~ = rounds then |
12 | return |
13 | end |
14 | end |
15 | if rounds = = keydown then |
16 | --Heres the script thats going to be executed after holding keydown |
17 | end |
18 | end |
I haven't tested if this works. And there might be a better way.