So, I want to learn how to execute a chunk of code when a player presses and holds a key but i'm not sure how to approach this, any help?
player = game.Players.LocalPlayer mouse = player:GetMouse() mouse.KeyDown:connect(function(key) print(key:byte()) if key == "f" then print("wassup") else print("hi") end end)
All you have to do is use a while loop to keep track of the time the key has been pressed. You also have to detect when the key has been "un-pressed" to reset that time. Like this :
player = game.Players.LocalPlayer mouse = player:GetMouse() fPressed = false timePressed = 0 mouse.KeyDown:connect(function(key) if key == "f" then fPressed = true end end) mouse.KeyUp:connect(function(key) if key == "f" then fPressed = false timePressed = 0 end end) while true do if fPressed then timePressed = timePressed + wait() if timePressed > 3 then print("F has been held for three seconds") end else wait() end end