Problem with Button1Up not firing quick enough

Move.MouseButton1Down:Connect(function()
   print('Down')
   IsMoving = true
end)

Mouse.Button1Up:Connect(function()
	print('Up')
	IsMoving = false
end)

Theoretically, every time you ‘click’ it should print Down and then Up. The point of this script is when a player clicks on a button, they start moving an object. When they release their mouse, it stops the item moving. Reason why I use Mouse.Button1Up instead of Move.MouseButton1Up is because if the players mouse isn’t on the button and they let go then it doesnt stop item moving.

Problem here is that if you click rapidly, you can cause it to print Down and not up (thus keeping IsMoving set to true, even tho you aren’t holding down the button)

3 Likes

Hello,

I tried in studio and there you go :

Move.MouseButton1Up:Connect(function()
	print('Up')
	IsMoving = false
end)

Move.MouseButton1Down:Connect(function()
   print('Down')
   IsMoving = true
end)

Move.MouseLeave:Connect(function()
	print("Player leaved the button")
	IsMoving = false
end)

I know you didn’t wanted to have the Move.MouseButtonUp but when you add another event of the mouse that leave the buttons, it should fix it.
It’s still also working when you click rapidly.
I hope it will fix it.

I can’t use MouseLeave, as when you move the object the mouse doesnt stay on the Move button (can’t figure out how to make move button actually follow the mouse)

Where is located your object? It is in a viewport frame?

The object is just a model in workspace and this code is running from a BillboardGui

Mmm Ok i think i founded a solution :

local uis = game:GetService("UserInputService")

local button = script.Parent.TextButton

local IsMoving

button.MouseButton1Down:Connect(function()
	print('Down')
    IsMoving = true
end)

uis.InputEnded:Connect(function(object)
	if object.UserInputType == Enum.UserInputType.MouseButton1 then
		print('Up')
    	IsMoving = false
	end
end)

Hope it works now

5 Likes