Detect if mouse is hovering any type of ImageButton?

Is it currently possible to detect if the mouse is hovering any clickable frame/button?

Let’s say when the player in my games runs a function when MouseButton1 is clicked/inputted, but if the mouse hovers over a clickable frame/button when clicked, then don’t detect the click?

Hovering and not-hovering:
image image

UserInputService.InputBegan:Connect(function(inputObject)
	-- check if mouse is hovering clickable image/button then return nothing to prevent below to run.
	if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
		print("Bla")
	end
end

You can use a boolean variable to keep track - if it’s hovering then you can set it to true. You then use this in your if statement - if (hovering = false) then -- do your click event .

2 Likes

But how would you detect hovering or is it already a property for a player’s mouse that can be used?

1 Like

GuiObject has an event called ‘MouseEnter’ which both Frame and ImageButton inherit.

10 Likes