MouseEnter/MouseLeave Alternative

Module link: hover (MouseEnter/MouseLeave alternative) - Roblox

Roblox’s GuiObject.MouseEnter and GuiObject.MouseLeave events don’t work very well, so I’ve made an alternative to them that is much more reliable.

I’ve tried to get its behavior as close as possible to the way MouseEnter and MouseLeave are supposed to work. If I’ve missed anything or you find any bugs let me know.

How to use

pretty much all you need to know:

--module can be put anywhere as long as it's require'able
local hover = require(game.ReplicatedStorage.Hover)

	print("mouse entered!")

	print("mouse left!")

To exclude ui objects, set the attribute hoverExclude to true on them. The attribute that is checked be changed in the config.

Excluded objects and their descendants will be ignored in the hover checks.

For example, a vignette image that covers the entire screen should be excluded so that it doesnt prevent objects below it from being hovered over.

All functions

Returns a signal that fires when the mouse hovers over uiObject

module.getEnterEvent(uiObject: GuiObject): RBXScriptSignal

Returns a signal that fires when the mouse stops hovering over uiObject

module.getLeaveEvent(uiObject: GuiObject): RBXScriptSignal

Destroys the BindableEvent that represents the uiObject’s enter event
(note that it can be re-bound by running module.getEnterEvent again)

module.unbindEnterEvent(uiObject: GuiObject)

Same as module.unbindEnterEvent but for the leave event.

module.unbindLeaveEvent(uiObject: GuiObject)

Completely removes uiObject from the module, unbinding both the enter and leave events
(this is what is called when a registered object is destroyed)

module.unRegister(uiObject: GuiObject)

Update 1.1:
• added exclusions

Only works with SurfaceGuis and BillboardGuis that are descendants of the player’s PlayerGui
• Performance doesn’t seem to suffer even with large amounts of registered ui objects
• Respects ClipsDescendants (works properly with scrolling frames!) and Rotation
• Gui objects are automatically removed from the module when they are destroyed


Not sure why but it’s not working for me, SurfaceGUI parented to PlayerGui. None of the events trigger.

Whats the script you’re using? Also if you have any UI elements covering the screen (fade to black thingies, vignettes, backgrounds, etc.) that could be blocking things below them from triggering make sure to exclude them.

(sorry i’m late i never check the devforum)