MouseLeave not firing when player moves cursor over text button to fast!

Hello! I have a Text Button Inside of a billboard GUI in my game, and I use Mouse Enter and the Mouse Leave functions to detect the mouse, but when the player moves their mouse over the button at a fast speed, the Mouse Leave function wont fire, but everything in the mouse enter function does, is there a way to prevent this?
My code (In starterplayerscripts):

function ButtonInfo(Desc)
	local data = game.MarketplaceService:GetProductInfo(Desc.Parent.ImportantValues.AssetId.Value, Enum.InfoType.Asset)
	Player.PlayerGui.Main.ButtonInfo.Info.ItemName.Text = data.Name
	Player.PlayerGui.Main.ButtonInfo.Info.Type.Text = Desc.Parent.ImportantValues.AssetType.Value
	print(data.IconImageAssetId)
	local assetId = Desc.Parent.ImportantValues.AssetId.Value
	Player.PlayerGui.Main.ButtonInfo.Icon.Image = "rbxthumb://type=Asset&id=" .. assetId .. "&w=420&h=420"
	Player.PlayerGui.Main.ButtonInfo.Info.Bucks.Amount.Text = data.PriceInRobux * 2
	if game.UserInputService.TouchEnabled == false then
		runService.RenderStepped:Connect(function()
			Player.PlayerGui.Main.ButtonInfo.Position = UDim2.new(0, Mouse.X + 20, 0, Mouse.Y) 
		end)
	else
		Player.PlayerGui.Main.ButtonInfo.Position = UDim2.new(0, Mouse.X + 20, 0, Mouse.Y) 
	end
	if game.UserInputService.TouchEnabled == true then
		Player.PlayerGui.Main.ButtonInfo.Position = UDim2.new(0, Mouse.X + 20, 0, Mouse.Y) 
	end
	Player.PlayerGui.Main.ButtonInfo.Visible = true
end
		Desc.MouseEnter:Connect(function()
			Desc:TweenSize(
				UDim2.new(0, 85,0, 70),
				"Out",
				"Quad",
				.3,
				true
			)
			ButtonInfo(Desc)
			Desc.MouseLeave:Connect(function()
				Desc:TweenSize(
					UDim2.new(0, 75,0, 60),
					"Out",
					"Quad",
					.3,
					true
				)
				Player.PlayerGui.Main.ButtonInfo.Visible = false
			end)
		end)
-- The function
function ButtonInfo(Desc)
	local data = game.MarketplaceService:GetProductInfo(Desc.Parent.ImportantValues.AssetId.Value, Enum.InfoType.Asset)
	Player.PlayerGui.Main.ButtonInfo.Info.ItemName.Text = data.Name
	Player.PlayerGui.Main.ButtonInfo.Info.Type.Text = Desc.Parent.ImportantValues.AssetType.Value
	print(data.IconImageAssetId)
	local assetId = Desc.Parent.ImportantValues.AssetId.Value
	Player.PlayerGui.Main.ButtonInfo.Icon.Image = "rbxthumb://type=Asset&id=" .. assetId .. "&w=420&h=420"
	Player.PlayerGui.Main.ButtonInfo.Info.Bucks.Amount.Text = data.PriceInRobux * 2
	if game.UserInputService.TouchEnabled == false then
		runService.RenderStepped:Connect(function()
			Player.PlayerGui.Main.ButtonInfo.Position = UDim2.new(0, Mouse.X + 20, 0, Mouse.Y) 
		end)
	else
		Player.PlayerGui.Main.ButtonInfo.Position = UDim2.new(0, Mouse.X + 20, 0, Mouse.Y) 
	end
	if game.UserInputService.TouchEnabled == true then
		Player.PlayerGui.Main.ButtonInfo.Position = UDim2.new(0, Mouse.X + 20, 0, Mouse.Y) 
	end
	Player.PlayerGui.Main.ButtonInfo.Visible = true
end

You have your mouse leave function inside your mounse enter function. Not sure why. Try this:

Desc.MouseEnter:Connect(function()
	Desc:TweenSize(
		UDim2.new(0, 85,0, 70),
		"Out",
		"Quad",
		.3,
		true
	)
	ButtonInfo(Desc)
end)

Desc.MouseLeave:Connect(function()
	Desc:TweenSize(
		UDim2.new(0, 75,0, 60),
		"Out",
		"Quad",
		.3,
		true
	)
	Player.PlayerGui.Main.ButtonInfo.Visible = false
end)

And your ButtonInfo(Desc) function needs o be above these two functions in the script so it can be found.

1 Like

I did try not having this, but still the same issue happens.

I defined local Desc = as a Frame that the script is inside of.

I removed two lines from the code here and it works every time for me:

local Desc = script.Parent

Desc.MouseEnter:Connect(function()
	Desc:TweenSize(
		UDim2.new(0, 85,0, 70),
		"Out",
		"Quad",
		.3,
		true
	)
	--ButtonInfo(Desc)
end)

Desc.MouseLeave:Connect(function()
	Desc:TweenSize(
		UDim2.new(0, 75,0, 60),
		"Out",
		"Quad",
		.3,
		true
	)
	--Player.PlayerGui.Main.ButtonInfo.Visible = false
end)

Does your script work if you --= the call to the function ButtonInfo(Desc) and just run the two functions above?

Hey, when the player goes over it fast with their mouse only the GUI that I am making visible when calling ButtonInfo(), the other item tween just fine

Would adding something like a debounce work?