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

MouseHover Function For Parts?

Asked by 8 years ago

Is there a function that works similarly to MouseHover in GUI's on parts?

For example, if I put my mouse over a part, it would do a MouseHover function?

This is critical for the development of my game.

2 answers

Log in to vote
2
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

You can do this using ClickDetectors. In a server script, inside of the part:

local click = Instance.new("ClickDetector", script.Parent)

click.MouseHoverEnter:connect(function(player) -- 'player' is the player who hovered.
    -- Do stuff
end)
click.MouseHoverLeave:connect(function(player)
    -- This is for when the mouse leaves the part.
end)
click.MouseClick:connect(function(player)
    -- And this is for when it's clicked.
end)

Hope this helped. For additional help, go here.

0
Thank you a million. KennySfromTitan 106 — 8y
0
No problem. Pyrondon 2089 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

While Pyrodon's answer is great for a server-sided script, most of the time, a MouseHover function would be used in some sort of a UI and therefore in a local script.

If that's your case, you can use PlayerMouse

player = game.Players.LocalPlayer;
mouse = player:GetMouse();

mouse.Move:connect(function()
    -- mouse.Target will point to the part the mouse is aimed at. You can check if it is the one you want.
    -- if mouse.Target.Name == 'PartThatTriggersAnActionWhenHovered' then print'action' end;
end);

Answer this question