Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

2 comments

1

use the user input service or the context action service

0

yup

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.