How can I fix my gui keep getting smaller when mouse click and leave too fast?

So whenever my mouse click and leave too fast on the button the size of the button keep staying at the MouseEnter size instead of the MouseLeave size. Here is the code:

	local NewOptionBtn = OptionButton:Clone()
	NewOptionBtn.Parent = DialogOptionsHolder
	NewOptionBtn.Name = OptionName
	NewOptionBtn.Text = OptionText
	NewOptionBtn.Size = UDim2.new(0, 0, 0, 0)
	
	Utils.Spring.target(DialogOptionsHolder, .5, 3, {
		Size = UDim2.new(0.217, 0, 0.776, 0)
	})
	Utils.Spring.target(NewOptionBtn, 1, 3, {
		Size = UDim2.new(1, 0, 0.19, 0)
	})
	
	task.delay(.25, function()
		if not CanClicksList[NewOptionBtn] then
			CanClicksList[NewOptionBtn] = true
		end
	end)
	
	Interface.OnHoverEnter(NewOptionBtn, function()
		if CanClicksList[NewOptionBtn] then
			print('a')
			Utils.Spring.target(NewOptionBtn, .35, 5, {
				Size = UDim2.fromScale(OptionButton.Size.X.Scale - .015, OptionButton.Size.Y.Scale - .015)
			})
		end
	end)
	
	Interface.OnHoverLeave(NewOptionBtn, function()
		if CanClicksList[NewOptionBtn] then
			print('b')
			Utils.Spring.target(NewOptionBtn, .35, 5, {
				Size = OptionButton.Size
			})
		end
	end)
	
	NewOptionBtn.MouseButton1Click:Connect(function()
		if CanClicksList[NewOptionBtn] then
			--CanClicksList[NewOptionBtn] = false
			print('c')
			task.spawn(function()
				Utils.Spring.target(NewOptionBtn, .35, 5, {
					Size = UDim2.fromScale(NewOptionBtn.Size.X.Scale - .015, NewOptionBtn.Size.Y.Scale - .015)
				})
				task.delay(.2, function()
					Utils.Spring.target(NewOptionBtn, .35, 5, {
						Size = UDim2.fromScale(OptionButton.Size.X.Scale - .015, OptionButton.Size.Y.Scale - .015)
					})
				end)
			end)
			
			if typeof(OptionCallback) == 'function' then
				OptionCallback()
			end
		end
	end)

I’ve had this issue with MouseEnter and MouseLeave too. They’re highly unreliable.
Use this open source module. It fixed all my problems, and will likely fix all of yours too.

My problem is not about MouseEnter and MouseLeave. The main problem here is when I click the mouse and leave the gui fast the size will be MouseEnter.

But thanks for your help. I will try it out and see if that fix the problem!!

Yes. MouseEnter and MouseLeave sometimes just don’t fire despite the player’s mouse being clearly outside the bounds of the guiObject. Replacing your MouseEnter events with the module I linked’s events should solve this issue. It’s pretty easy to implement too, basically exactly like the native roblox MouseEnter/MouseLeave.

Hello there, I have tried it again and it doesn’t work as I expected.

Here is the script now:

	local NewOptionBtn = OptionButton:Clone()
	NewOptionBtn.Parent = DialogOptionsHolder
	NewOptionBtn.Name = OptionName
	NewOptionBtn.Text = OptionText
	NewOptionBtn.Size = UDim2.new(0, 0, 0, 0)
	
	Utils.Spring.target(DialogOptionsHolder, .5, 3, {
		Size = UDim2.new(0.217, 0, 0.776, 0)
	})
	Utils.Spring.target(NewOptionBtn, 1, 3, {
		Size = UDim2.new(1, 0, 0.19, 0)
	})
	
	task.delay(.25, function()
		if not CanClicksList[NewOptionBtn] then
			CanClicksList[NewOptionBtn] = true
		end
	end)
	
	local MouseEnter, MouseLeave = Interface.MouseEnterLeaveEvent(NewOptionBtn)
	
	--Interface.OnHoverEnter(NewOptionBtn, function()
	--	if CanClicksList[NewOptionBtn] then
	--		print('a')
	--		Utils.Spring.target(NewOptionBtn, .35, 5, {
	--			Size = UDim2.fromScale(OptionButton.Size.X.Scale - .015, OptionButton.Size.Y.Scale - .015)
	--		})
	--	end
	--end)
	
	--Interface.OnHoverLeave(NewOptionBtn, function()
	--	if CanClicksList[NewOptionBtn] then
	--		print('b')
	--		Utils.Spring.target(NewOptionBtn, .35, 5, {
	--			Size = OptionButton.Size
	--		})
	--	end
	--end)
	
	MouseEnter:Connect(function()
		if CanClicksList[NewOptionBtn] then
			print('a')
			Utils.Spring.target(NewOptionBtn, .35, 5, {
				Size = UDim2.fromScale(OptionButton.Size.X.Scale - .015, OptionButton.Size.Y.Scale - .015)
			})
		end
	end)
	
	MouseLeave:Connect(function()
		if CanClicksList[NewOptionBtn] then
			print('b')
			Utils.Spring.target(NewOptionBtn, .35, 5, {
				Size = OptionButton.Size
			})
		end
	end)
	
	NewOptionBtn.MouseButton1Click:Connect(function()
		if CanClicksList[NewOptionBtn] then
			--CanClicksList[NewOptionBtn] = false
			print('c')
			task.spawn(function()
				Utils.Spring.target(NewOptionBtn, .35, 5, {
					Size = UDim2.fromScale(NewOptionBtn.Size.X.Scale - .015, NewOptionBtn.Size.Y.Scale - .015)
				})
				task.delay(.2, function()
					Utils.Spring.target(NewOptionBtn, .35, 5, {
						Size = UDim2.fromScale(OptionButton.Size.X.Scale - .015, OptionButton.Size.Y.Scale - .015)
					})
				end)
			end)
			
			if typeof(OptionCallback) == 'function' then
				OptionCallback()
			end
		end
	end)

Update. I think this is the main reason to the problem.

			task.spawn(function()
				Utils.Spring.target(NewOptionBtn, .35, 5, {
					Size = UDim2.fromScale(NewOptionBtn.Size.X.Scale - .015, NewOptionBtn.Size.Y.Scale - .015)
				})
				task.delay(.2, function()
					Utils.Spring.target(NewOptionBtn, .35, 5, {
						Size = UDim2.fromScale(OptionButton.Size.X.Scale - .015, OptionButton.Size.Y.Scale - .015)
					})
				end)
			end)

Yes… you’re correct!! I misdiagnosed the error here. Oops

It seems that the script sets the size of the guiObject .2 seconds after a click, probably to make the gui button get large then small again after clicked.
If the player moves their mouse away within these .2 seconds, it will bug out.

One solution could be to:

  • Check the size of the GuiObject in the delay(.2, function(), to ensure that it doesn’t set the guiObject’s size to too large.

Alr. I will try to see if it works now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.