How to detect if a keybind is held down?

So, I’ve seen quite a few posts about this but none of them really work. In some places I’ve seen people using UserInputService:IsKeyDown(keycode), but it doesn’t work at all. It’d be really helpful if there’s any solutions to this problem. Thanks!

1 Like
UserInputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.E then
print (" holding e")
end
end)
1 Like

It doesn’t work. It prints out holding e, but only once.

use inputEnded and InputBegan
UserInputService.InputBegan mean the player pressed on key
UserInputService.inputEnded mean player stop holding the key

UserInputService.InputBegan:Connect(function(key)
print ("player start holding "..key.KeyCode)
end
end)
UserInputService.inputEnded:Connect(function(key)
print ("player stop holding "..key.KeyCode)
end
end)
1 Like

IsKeyDown should work properly, are you sure you’re using it correctly? Showing a snippet of your script would help.

That’s because the event only ran once. If you want it to continually loop, then you have to construct a while loop to do so.

Thanks, I was just messing around with it, and yeah got the solution! Thanks m8!