✓ Accepted answer
You can use the UserInputService to detect if a key is being pressed, then you can make it do what you want. An example is shown here :
This is the InputBegan which detects when the key is pressed
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(Input, gameProcessedEvent)
local KeyCode = Input.KeyCode
if not gameProcessedEvent then
if KeyCode == Enum.KeyCode.F then
end
end
end)
This is the InputEnded which detects when the key is released
local UIS = game:GetService("UserInputService")
UIS.InputEnded:Connect(function(Input, gameProcessedEvent)
local KeyCode = Input.KeyCode
if not gameProcessedEvent then
if KeyCode == Enum.KeyCode.F then
end
end
end)