Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I made it so something works when you hold down a button?

Asked by
Txeer 46
5 years ago

How do I make it so something only works when you are holding down button?

1
use the user input service or the context action service radusavin366 617 — 5y
0
yup Oficcer_F 207 — 5y

1 answer

Log in to vote
0
Answered by
piRadians 297 Moderation Voter
5 years ago

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
Ad

Answer this question