Hovering Module | Better alternative to MouseEnter and MouseLeave!

hovering module
by @coolifysz


I discovered this a while ago, I didn’t know a lot of people discovered it. But I made it a module anyways because I included something else!


Guide

First you need to require the module and then add this:

local HoveringModule = require(game:GetService("ReplicatedStorage").HoveringModule)
local New = HoveringModule.new() -- any variable name, just add the .new() function.

Inside of the (), you need to put a GuiObject, it can be a frame, textbox, button, anything!

The function that we added returns 2 events, HoverStarted and HoverEnded. Here’s how to use them!

So just like any other RBXScriptSignal, we connect the event to a function.

New.HoverStarted:Connect(function()
end)

New.HoverEnded:Connect(function()
end)

You can put anything inside of those functions, like a text that pop up, or the color changes, the image changes, etc. Here’s an example, I used this code to test out the functions.

local frame = script.Parent
local hoveringmodule = require(game:GetService("ReplicatedStorage").HoveringModule)
local new = hoveringmodule.new(frame)

new.HoverStarted:Connect(function()
	frame.BackgroundColor3 = Color3.fromRGB(255,0,0)
end)

new.HoverEnded:Connect(function()
	frame.BackgroundColor3 = Color3.fromRGB(255,255,255)
end)

What this does, is when the mouse enters the frame turns red, and when the mouse leaves the frame turns back to normal. Try this all you want!

and that’s the best alternative to mouseenter and mouseleave, ask any questions!


Other things to note:

  • This has no full-support on mobile and will only hover when the user is holding down on the frame.
  • Since this uses InputBegan and InputEnded, TextBoxes will have a frame in them to detect ONLY the mouse hovering over them and not entry.
6 Likes

Why is this a better alternative to MouseEnter/MouseLeave?

1 Like

How is this better than the regular mouse enter/leave events. You have to create a constructor when I could just reference my UI elements instead.

This seems essentially the same as using mouse enter/leave except I would also need to add a constructor for each element.

^^^

2 Likes

MouseEnter and MouseLeave don’t work as well, they are super glitchy and when I use it the MouseLeave events don’t even fire.

Even other people made alternatives.

1 Like

I think it’s just your code, the events work perfectly fine. This module just complicates the event for no reason as it has no difference.

Edit: I just checked the link and that post is from 2018, 5 years ago!!
Maybe 5 years ago it wasn’t reliable, but we are way past 2018.

2 Likes

The question is, has Roblox really improved it though? Because I personally still find issues.

2 Likes

Could you provide some details? Like your UI Objects and Script? That would be really helpful for all of us.

If a user speeds through a list of Hover elements, no MouseLeave events will fire, and sometimes if you just have two next to each other and you can back and forth, it won’t fire.

Never mind, I stand corrected. I tested it out and they improved it a ton.

Oh wow, I tested it too and they actually did improve it. I went to check if the Release Notes said they improved it and none of it did, did they improve it out of the blue?

1 Like

Yes, they have improved it. As I said earlier, it’s more of a scripting problem than the actual event problem.

1 Like