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

How can one use UserInputService to tell if a mouse button has been released?

I am aware that you can use UserInputService.InputBegan to tell if a mouse button has been clicked but I am unaware if you can use it to tell if the mouse is up. Would I use InputEnded?

9 comments

0

you dont need uis for that, there is an event on the mouse for that

0

mouse.button1up or mouse.button2up

0

^ apparently that's not as good according to renowned scripters

0

Yes, but I thought It was more efficient to use UIS, am I incorrect?

0

im not sure about the reasons

0

Yes @Stephen, exactly what I'm talking about

0

So what should I use I guess?

0

mouse.Button1Up is the best to use, use a debounce to check if it is being held

1

The Mouse class is going to eventually be deprecated. UserInputService is shaping up to be(and should be)the best way of handling user input, mouse or not.

2 answers

To achieve this you can use InputEnded as shown here:

local clickHolding = true --Just for example

UserInputService.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		clickHolding = false
	end
end)

4 comments

0

that won't work because you can't set multiple words to be one variable ("click holding" can't be a variable)

0

Did you just answer your own question?

0

Sorry fixed @gewehrrenben and yes, mostly so other who needed to know could search it and find out @DaCrazyDev .

0

Go to the forums for that.

or you could ignore user input service and use

local plr = game.Players:WaitForChild("LocalPlayer")
local mouse = plr.GetMouse()

mouse.Button1Down:Connect(function()
	-- what happens when player holds down left button
end)

mouse.Button1Up:Connect(function()
	-- what happens when player releases left button
end)

--You could use to do the right button, use 
	--Mouse.Button2Down:Connect(function()
--for right button down

2 comments

3

That's not the point of the question, though?

0

Exactly, plus as shown above, that will soon be depreciated.

This discussion is preserved as it was. New answers, comments, and votes are closed.