Gui mouse enter not working

Hello developers, I am currently working on a gui function which should run everytime mouse hovers over the button. However the function doesn’t detect even though the mouse hovers over the button. Is there a way to fix this? Thanks.

local function HoverIn(button)
	print("func ran") -- doesn't run.
end


for _, button in CollectionService:GetTagged("HoverElement") do
	button.MouseEnter:Connect(HoverIn)
end

1 Like

roblox’s mouseEnter and mouseLeave function is extremely unreliable, so you need custom behavior for this to work
I will leave the model here (props to the creator, don’t worry he is legit):

how to use:

local started, ended = hovermodule.MouseEnterLeaveEvent(insert gui element here)
	started:Connect(function()
		-- mouse enter
	end)

	ended:Connect(function()
		-- mouse leave
	end)
1 Like

Thanks for the reply. However I am not sure about using it, I didn’t used collection service instead and it works fine now.

1 Like

It may be that you’re calling CollectionService:GetTagged too early before the buttons have a chance to be tagged, especially when you’re on the client side which is downloading the GUI data. Try adding a task.wait(1) before calling GetTagged.

Also, as @neweve2323 mentioned, it’s not recommended to use MouseLeave/MouseEnter as they are very unreliable. While the Hovering Module is great, if you want an alternative, I recommend to use TextButton.InputBegan/InputEnded/InputChanged, which is just as reliable (see defaultio’s post).

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.