Holding (mouse button)

hey, i want to know how you can make that you can hold and not only click.
my script:

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
"the script here"
end

~ maini

Make a variable to determine if the mouse is being held them, make but the code InputBegan and in InputEnded set the variable to true or false, depending on if the mouse is held of released, and just make the code inside of the InputBegan loop, except, keep the line that sets the variable to true outside of it

1 Like

can you make an example script? xd

I think you wanted something like this?

local UIS = game:GetService("UserInputService")
local held = false

UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		held = true
		while held == true do
			"the script here"
			game:GetService("RunService").RenderStepped:Wait()
		end
	end
end)

UIS.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		held = false
	end
end)
5 Likes

This is not a place to be spoonfed, try their example out for yourself.

As they stated, you need to use InputBegan and InputEnded, this is pretty self explanatory as you wait from when the mouse started being pressed InputBegan and when the mouse stopped being pressed InputEnded.

1 Like