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)


This only happens on PC

MouseLeave is notoriously horrible. Moving your mouse too quickly will result in what you’re experiencing. There are work arounds for this but honestly if you want to keep it simple there is a pretty good module that I would recommend you try instead. I use it sometimes and honestly it works for my use cases.

This doesn’t work for me, is there another way?

local tweens = game:GetService("TweenService")

local guiObject = script.Parent

local tween

guiObject.MouseEnter:Connect(function()
	if tween then tween:Cancel() end
	tween = tweens:Create(guiObject, TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Size = UDim2.new(0.323, 0, 1.075, 0)})
	tween:Play()
end)

guiObject.MouseLeave:Connect(function()
	if tween then tween:Cancel() end
	tween = tweens:Create(guiObject, TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Size = UDim2.new(0.302, 0, 1.005, 0)})
	tween:Play()
end)

Make sure the UDim2 values that describe the GuiObject’s goal sizes are correct.

1 Like

MouseLeave and MouseEnter works for devices with mouse only, you cannot expect a mobile user to have a mouse, so its obvious that it does not work on mobile, its not a bug either an issue, its a fact

Not just that, there are lot more which don’t work on mobile and tablets like
MouseButton1Down does not work on mobile MouseButton1Up

You should go for MouseButton1Click
I know this is not okay for some developers but, however you can use a custom module made by other developers or make your own if you want to fix this

Hi, you can try changing false to true. I don’t suggest doing this in a script that controls the entire gui because it can mess up other tweens. This changes if the tweens will overright one another, otherwise one would have to finish before playing another. (if you’re lazy and just want to copy it)

script.Parent.MouseEnter:Connect(function()
	script.Parent:TweenSize(
		UDim2.new(0.323, 0,1.075, 0),
		"Out",
		"Quad",
		.2,
		true -- Enables overright (don't recommend using it a script controlling the entire gui)
-- Good to put in a seperate script
	)	
end)
script.Parent.MouseLeave:Connect(function()
	script.Parent:TweenSize(
		UDim2.new(0.302, 0,1.005, 0),
		"Out",
		"Quad",
		.2,
		true
	)	
end)

See if this works

	Button.InputBegan:Connect(function(Input)
		if Input.UserInputType == Enum.UserInputType.MouseMovement or Enum.UserInputType.Touch then
			print("In!")
		end
	end)
	Button.InputEnded:Connect(function(Input)
		if Input.UserInputType == Enum.UserInputType.MouseMovement or Enum.UserInputType.Touch then
			print("Out!")
		end
	end)