I need to get the object in the workspace the mouse is hovering over. How can I do this?
You can use the .Target property of Mouse
. For conventional use, apply a .Move signal to perpetually keep track of what the Cursor is hovering over.
local Player = game:GetService("Players").LocalPlayer local Cursor = Player:GetMouse() Cursor.Move:Connect(function() local Target = Cursor.Target if (Target ~= nil) then print(Target.Name) end end)
I believe using ClickDetector.MouseHoverEnter
will solve your problem, and you could use it in your script like this:
local part = game.workspace.Part --the part you want the mouse to hover over (if it’s in a different place or has another name just change that) local ClickDetector = Instance.new("ClickDetector") --makes a click detector ClickDetector.Parent = part --the parent of the click detector (set this to your part name) ClickDetector.MaxActivationDistance = 10 --the distance of studs that this script can work from ClickDetector.CursorIcon = “ImageId” --this is optional, if you want the mouse/cursor to change then you can put whatever ID in there. (If you don’t want it just delete it) ClickDetector.MouseHoverEnter:Connect(function() part.Transparency = .5 --this is just an example of what will happen when someone hovers, change this to whatever you want to happen when the player hovers over it end)