I was wondering if there's a function like KeyHold
, kind of like KeyDown
but for when you're holding a key.
Example:
local Player = game.Players.LocalPlayer Player:GetMouse().KeyHold:connect(function(keydown) local key = string.lower(keydown) if key == "c" then print(math.random(1,9999)) end end)
When I tried using KeyHold it gave me this error.
KeyHold is not a valid member of PlayerMouse
Any way I can achieve this? Any help appreciated.
Sorry I can't explain any better.
You can easily achieve this with a debounce, like so:
local mouse = game.Players.LocalPlayer:GetMouse() local holding = false mouse.KeyDown:connect(function(key) key = key:lower() if key == "f" then holding = true end end) mouse.Up:connect(function(key) key = key:lower() if key == "f" then holding = false end end while holding == true do -- code end