Looping until input ended

Hello, I know this is a very stupid question, but how could I make it so a function will repeat until an input ends? I tried

UIS.InputBegan:Connect(function(input)
	if input == Enum.KeyCode.Space then
		repeat Shoot() until UIS.InputEnded(Enum.KeyCode.Space)
	end
end)

If anybody could help, I’d greatly appreciate it. Thanks!

There is a property of UIS which is IsKeyDown, it returns the key that is currently hold (It’s a boolean). So probably something like this should work:

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Space then
		while UIS:IsKeyDown(Enum.KeyCode.Space) do
			Shoot()
			wait() -- add a number, however you like
		end
	end
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.