Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
Prioxis 673 Moderation Voter
9 years ago

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

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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).

0
ah thank you! :D Prioxis 673 — 9y
Ad
Log in to vote
2
Answered by 9 years ago

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!

Answer this question