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.
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.
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.
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);
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
Thank you a million.
No problem.