Impossible to accurately get M1 down

I’m attempting to detect mouse1 held down but it’s extremely inaccurate (randomly stops)

while UIS:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) or UIS:IsMouseButtonPressed(0) do

(^ code I’m running)

If anyone knows a suitable alternative, that would be great

I’m not sure if it’s cause of the UIS:IsMouseButtonPressed(0), but it’s probably not the case, maybe.

An alternative you can probably do is use InputBegan and InputEnded to set a variable that determines if you’re holding mouse 1 down

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

UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		mouseheld = true
	end
end)

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

For example, and in your loop, just do while mouseheld do

in this case, the UIS:IsMouseButtonPressed(0) if it worked or not would not cause a problem because of the or statement.

I kinda regretted doing it this way but I’ll see if its more accurate

Then that 2nd condition is probably not the problem, so it’s probably just a bit of inaccuracies with the function. My code should work since it only changes it is you hold and release the mouse. If that still doesn’t work, then you can maybe try using the mouse object’s events

1 Like