MouseLeave Function Not working!

Hello, I made a script they would tween a Gui, but when I call the MouseLeave Function it won’t run sometimes.

script.Parent.MouseEnter:Connect(function()
	script.Parent:TweenSize(
		UDim2.new(0.323, 0,1.075, 0),
		"Out",
		"Quad",
		.2,
		false
	)	
end)
script.Parent.MouseLeave:Connect(function()
	script.Parent:TweenSize(
		UDim2.new(0.302, 0,1.005, 0),
		"Out",
		"Quad",
		.2,
		false
	)	
end)


Are you moving your mouse fast? A known issue with MouseLeave is if you move your mouse too fast, it doesn’t fire with 100% accuracy.

Yes I am, Thats when it breaks, is there a way to fix it?

Use this module: Fed up with MouseEnter and MouseLeave not working? Here's a module for you!

1 Like

Well, not really but there is a pretty good module I’d recommend that I used ages ago and worked decently for me.

If you want some example code with it, let me know and I’ll see what I can do.

Im using this module for ScrollingFrames in my game, and sometimes I see error: Attempt to index RBXScriptConnection with :GetMouse(). Error stops the script from running, so your UI will be broken.
Thats because of the first line in the script:

local Player = game.Players.LocalPlayer or game.Players:GetPropertyChangedSignal("LocalPlayer")

Sometimes LacalPlayer property not loading in time, so it takes the connection instead.
To fix this, replace the first line with

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

if not Player then
   repeat
      Players.Changed:Wait()
      Player = Players.LocalPlayer
   until Player
end

Set the override parameters to true.

2 Likes