How do I make it so something only works when you are holding down button?
COMMUNITY QUESTION
How do I made it so something works when you hold down a button?
1 answer
I would use UserInputService.
local uis = game:GetService("UserInputService")
local active = false
uis.InputBegan:Connect(function(input) -- first parameter is the InputObject
if input.KeyCode == Enum.KeyCode.Q then-- Change "Q" to whatever key you'd like to.
active = true
repeat -- repeats until it's false
wait(1) -- make sure there is a wait or else it will crash your studio
print('a')
until
active == false
end
end)
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
active = false -- sets it to false when button is released
end
end)
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
use the user input service or the context action service
yup