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!
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
local UIS = game:GetService("UserInputService")
UIS.InputBegan:connect(function(keycode)
if keycode.keyCode == Enum.KeyCode.w then -- Change w to the key you want
local keydown = 0
for rounds = 1,(5 * 4) do --change 5 to the amount of seconds you want
wait(0.25)
if keycode.keyCode == Enum.KeyCode.w then -- Change w to the key you want
keydown = keydown + 1
end
if keydown ~= rounds then
return
end
end
if rounds == keydown then
--Heres the script thats going to be executed after holding keydown
end
end
I haven't tested if this works. And there might be a better way.
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
You could also do keydown and keyup events, That probably works better
great answer
Thx bash:)