Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can you use MouseEnter() on a physical part??

No I haven't tried anything just asking a QUESTION can you use MouseEnter and MouseLeave on a physical part like in some games when you mouse over something and trigger a gui...

All I wanted to know

2 answers

✓ Accepted answer

As an alternative to ClickDetectors, you can use a combination of an event, UserInputService.InputChanged, and the Mouse.Target property:

local uis = game:GetService("UserInputService")
local Mouse = game:GetService("Players"):GetMouse()

local lastObject
uis.InputChanged:connect(function()
	if lastObject ~= Mouse.Target then
		if lastObject then
			--MouseLeaveFunction(lastObject)
		end
		if Mouse.Target then
			--MouseEnterFunction(Mouse.Target)
		end
		lastObject = Mouse.Target
	end
end)

InputChanged fires when the Mouse moves or scrolls, or wherever a mouse&keyboard input doesn't have a definite 'on' or 'off' state (such as a Key being pressed or not).

1 comment

0

ah thank you! :D

Yes, with ClickDetectors.

ClickDetectors have 2 events similar to MouseEnter and MouseLeave:

MouseHoverEnter

MouseHoverLeave

You use these events just like how you would use the MouseEnter and MouseLeave event in Gui objects.

Read more about ClickDetectors here: ClickDetectors

Hope this helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.