How can I get MouseEnter and MouseLeave to work properly?

  1. What do you want to achieve?
    Make the item slots tween to be a bit bigger when hovering over them.

  2. What is the issue?
    https://gyazo.com/1a7dbfe08d358514bfbf8c1b8015d034

  3. What solutions have you tried so far?
    I tried both modules from these posts:
    Hovering Module | Better alternative to MouseEnter and MouseLeave!
    Fed up with MouseEnter and MouseLeave not working? Here's a module for you!

Neither of them changed anything and it still worked the same as MouseEnter and MouseLeave

1 Like

Can you show your code, cus the category is named #help-and-feedback:scripting-support for a reason. And you don’t need any of those modules since they were built to be used years ago (2018) when Roblox’s MouseEnter and MouseLeave signals were downright awful, however afaik they improved it a ton since then.

1 Like

The code with the functions:

for i,Slot in pairs(Slots) do
	local Object = Slot.VisualFrame
	
	
	
	
	Object.MouseEnter:Connect(function()
		if Object.Visible == true then
			if not table.find(SlotsTweened, Object) then
				table.insert(SlotsTweened, Object)
				
				PlaySound(SlotHoverSFX)
				TweenSlot(Object, "In")
			end
		end
	end)
	
	
	Object.MouseLeave:Connect(function()
		if Object.Visible == true then
			if table.find(SlotsTweened, Object) then
				table.remove(SlotsTweened, table.find(SlotsTweened, Object))
				
				TweenSlot(Object, "Out")
			end
		end
	end)

The TweenSlot function:

local function TweenSlot(Slot, Mode)
	local Goal
	
	if Mode == "In" then
		Goal = UDim2.new(
			0,
			Slot.Size.X.Offset * HoverSettings["Size Increase"],
			0,
			Slot.Size.Y.Offset * HoverSettings["Size Increase"]
		)
	elseif Mode == "Out" then
		Goal = UDim2.new(
			0,
			Slot.Size.X.Offset / HoverSettings["Size Increase"],
			0,
			Slot.Size.Y.Offset / HoverSettings["Size Increase"]
		)
	end
	
	
	if Goal then
		Slot:TweenSize(
			Goal,
			HoverSettings["Easying Direction"],
			HoverSettings["Easying Style"],
			HoverSettings["Tween Time"],
			true
		)
	end
end
1 Like

Denounce is gonna be really weird because if you quickly drag the mouse across, it won’t decrease in size again, and it will be like all frames are hovered over.

1 Like

Adding a debounce didn’t work, the main issue is that when the mouse moves quickly it skips frames and won’t fire the events.

1 Like

I suggest you instead try to use fixed sizes. Instead of button.Size + UDim2 or something, you skip including button.Size

1 Like

try doing smtg like this

local button
local MouseEnterTween = game.TweenService:Create(button, TweenInfo.new(--[[your tween info]]--), {Size = UDmi2.new()})
local MouseLeaveTween = game.TweenService:Create(button, TweenInfo.new(--[[your tween info]]--), {Size = UDmi2.new()})

button.MouseEnter:Connect(function()
MouseLeaveTween:Pause()
MouseEnterTween:Play()
end)

button.MouseLeaveConnect(function()
MouseEnterTween:Pause()
MouseLeaveTween:Play()
end)

That kind of worked so it can’t get infinitely small or big but it still stays stuck.

It uses TweenSize instead of TweenService:Create so you can’t pause or play it.

First off I gotta recommend using Scale instead of Offset, because otherwise your buttons are gonna be chaos on larger or smaller devices.

Then, instead of tweeting to button size plus something, just tween to an already calculated value.

I mean replace TweenSize with TweenService

It’s unnecessary to use tween service in this case, and he might as well use TweenSize, because the override property allows to override the current tween.

Oh yea he can use that too

Might be caused by dynamic sizing your module does, try this:

@Z3tsa Replace original offset at the top with the offset of your slot.

local OriginalOffset = UDim.new(0, 0)

local function TweenSlot(Slot, Mode)
	local Goal
	
	if Mode == "In" then
		Goal = UDim2.new(
			0,
			OriginalOffset.X * HoverSettings["Size Increase"],
			0,
			OriginalOffset.Y * HoverSettings["Size Increase"]
		)
	elseif Mode == "Out" then
		Goal = UDim2.new(
			0,
			OriginalOffset.X,
			0,
			OriginalOffset.Y
		)
	end
	
	
	if Goal then
		Slot:TweenSize(
			Goal,
			HoverSettings["Easying Direction"],
			HoverSettings["Easying Style"],
			HoverSettings["Tween Time"],
			true
		)
	end
end