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.