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

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

Asked by 5 years ago
Edited 5 years ago

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?

0
you dont need uis for that, there is an event on the mouse for that theking48989987 2147 — 5y
0
mouse.button1up or mouse.button2up theking48989987 2147 — 5y
0
^ apparently that's not as good according to renowned scripters DaCrazyDev 444 — 5y
0
Yes, but I thought It was more efficient to use UIS, am I incorrect? Stephenthefox 94 — 5y
View all comments (5 more)
0
im not sure about the reasons DaCrazyDev 444 — 5y
0
Yes @Stephen, exactly what I'm talking about DaCrazyDev 444 — 5y
0
So what should I use I guess? Stephenthefox 94 — 5y
0
mouse.Button1Up is the best to use, use a debounce to check if it is being held greatneil80 2647 — 5y
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. User#19524 175 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)

0
that won't work because you can't set multiple words to be one variable ("click holding" can't be a variable) User#22604 1 — 5y
0
Did you just answer your own question? DaCrazyDev 444 — 5y
0
Sorry fixed @gewehrrenben and yes, mostly so other who needed to know could search it and find out @DaCrazyDev . Stephenthefox 94 — 5y
0
Go to the forums for that. hiimgoodpack 2009 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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
3
That's not the point of the question, though? proIua 32 — 5y
0
Exactly, plus as shown above, that will soon be depreciated. Stephenthefox 94 — 5y

Answer this question