This is not a request, I want an explanation
How would you trigger something ( make something happen ) when someones mouse is over a part. Links to wiki posts, what it would use,and an explanation of what everything does would be helpful And so would an example, thanks!
This is a bit of a tougher concept. There are however many ways to go at it.
The first way (my personal way) is to use the line mouse.Target.Name
, put an if
afterwards, and then have it hard coded to check for certain words. From there, you could then set a variable (in lighting, for instance) to a value if the name of the part equals a name in a table or list.
From there, add a repeat wait() until game.Lighting.variable.Value == true
or a Changed
event to run the designated code.
It will require being in a LocalScript
, and will need mouse defined (local mouse = game.Players.LocalPlayer:GetMouse()
)
Or, if you're not looking for specifics, and just to check if it's a part, you could just do this --
if mouse.Target ~= nil then end
Now, the second way is a bit more professional, however, it's definitely more complex. That way would be Raycasting
. It's great with detecting parts and many other detection sources (best used with a tool of some sort). Here's a good wiki page for general Raycasting, and what looked to be a good Raycasting basics page to help you get started.
The first example in the basics might already be similar to what you're looking for.
I wouldn't fully suggest using these methods without it being a tool or a LocalScript
inside of StarterGui
, but maybe there's a workaround I'm not thinking of at the moment.
Those are what I believe to be the best ways to check for parts, as both have their strengths and weaknesses. I'm sure there are more, but they're either inferior to both listed above, or I'm not aware of them.
If you have any other questions, feel free to ask, and I'll answer to the best of my knowledge. Good luck in your endeavors!
Use the Changed event:
function onHover(Part) print("Mouse hovering above " .. Part.Name); end mouse.Changed:connect(function(Property) if Property == "Target" and mouse.Target then -- if Target is changed, and it exists onHover(mouse.Target); end end);
You can also do it with coroutines, if you like:
getNextHover = coroutine.wrap(function() repeat repeat until mouse.Changed:wait() == "Target" and mouse.Target; coroutine.yield(mouse.Target); until false; end); while true do onHover(getNextHover()); end