GuiObject.InputBegan InputObject does not update for MouseButton1

The InputObject passed by GuiObject.InputBegan will not properly update its state or position if the InputType is “MouseButton1”

Expected Behavior

If you get an inputObject from GuiObject.InputBegan by holding down your mouse, the position and state of that inputObject should change as you move the mouse while the button is held down

Actual Behavior

The inputState of the inputObject remains “Began” as long as the mouse is held down, and the position does not change from the initial button down position.

Demonstration

I ran into this bug during a dev stream. Here’s a helpful video demonstration that clearly shows the actual behavior, the expected behavior and then the code at the end:

Code:

	volumeFrame.bar.InputBegan:connect(function(input)
		if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
			
			local startPointX = volumeFrame.bar.AbsolutePosition.X
			local endPointX = volumeFrame.bar.AbsolutePosition.X + volumeFrame.bar.AbsoluteSize.X
			
			print("INPUT START", input.UserInputState, input.Position)
			
			while input.UserInputState ~= Enum.UserInputState.Cancel and input.UserInputState ~= Enum.UserInputState.End do
				
                print("INPUT TICK", input.UserInputState, input.Position)

				local inputPointX = input.Position.X - startPointX
				volumeFrame.bar.slider.Position = UDim2.new(math.clamp(inputPointX / (endPointX - startPointX), 0, 1), 0, 0.5, 0)
				runService.Heartbeat:wait()
			end

            print("INPUT ENDED", input.UserInputState)
			
		end
	end)

The exact same code works perfectly well with a “Touch” inputObject, but not with a “MouseButton1” input object.

The MouseButton1 input object will continue to read the position of the initial button down, and will not update as the mouse is moved.

4 Likes

I can see how this is confusing and I think we can do a few things to make this better, but as of right now this is working as intended.

The big difference between touch input and mouse input is button state changes and mouse movements are separated into two different input types, whereas touch is inherently one type of action. So, if you listen to mouse button 1 down, you’ll need to grab MouseMovement InputObject from UserInputService.InputChanged.

I think we could potentially add positional updates to the mouse button inputobjects, as well as make a getter for mousemovement, as it is always the same InputObject throughout a client’s lifetime.

1 Like

edit: I think I misunderstood what you meant by “intended behavior.” From a developer’s perspective, this is unintended. I can see how its more of a “missing feature” internally.

This would be very helpful. As a developer, I want to know the current position of an input object, not just the position it was at when it started. What we have now is entirely misleading.

To a user, dragging the mouse is one type of action the same way that sliding your finger is.

3 Likes