Problem with MouseLeave

I’ve seen many people complaining about the unreliability of the “.MouseLeave”.
So, I was trying to do that, when you hover on a frame with the mouse, it gets bigger, and when you stop hovering it, it returns to the “normal size”.

When I move the mouse very slowly it works, but when I move it a little bit faster it just stop working.

Here’s a GIF showing the issue:
https://gyazo.com/ea04f28499758c537da8175046b7292e

Is there any way to fix it?

Here’s the simple script I used:

local frame = script.Parent.Parent
local btn = script.Parent

btn.MouseEnter:Connect(function()
	frame:TweenSize(UDim2.new(0.42, 0, 0.48, 0), "Out", "Quint", 0.5)
end)

btn.MouseLeave:Connect(function()
	frame:TweenSize(UDim2.new(0.405, 0, 0.456, 0), "Out", "Quint", 0.5)
end)

Thanks in advance!

1 Like

No, it’s just broken like that. You’ll have to write your own logic for detecting when the mouse enters/leaves a GUI object.

1 Like

As @ThanksRoBama said, it’s broken, but I don’t think that way.

You may do this for MouseEnter function:

frame:TweenSize(UDim2.new(0.42, 0, 0.48, 0), "Out", "Quint", 0.5, true)

and this for MouseLeave function:

frame:TweenSize(UDim2.new(0.405, 0, 0.456, 0), "Out", "Quint", 0.5, true)

The true at the end lets the tweens override other tweens; for more info - see this: GuiObject | Documentation - Roblox Creator Hub

After you made the changes your code should look like this:

btn.MouseEnter:Connect(function()
	frame:TweenSize(UDim2.new(0.42, 0, 0.48, 0), "Out", "Quint", 0.5, true)
end)

btn.MouseLeave:Connect(function()
	frame:TweenSize(UDim2.new(0.405, 0, 0.456, 0), "Out", "Quint", 0.5, true)
end)

Let me know if this helps!

16 Likes

Myself and a few others have come across the exact same issue. Luckily, @madattak was kind enough to make a module for us to use. Have a look at this post. This module has worked perfectly for me and diminished the probability of MouseEnter/MouseLeave not firing. Let me know if you have any trouble with setting it up.

2 Likes

Im a bit late but adding a wait usually helps

btn.MouseLeave:Connect(function()
wait(.2)
	frame:TweenSize(UDim2.new(0.405, 0, 0.456, 0), "Out", "Quint", 0.5)
end)