Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I get the name of a part the mouse is hovering over when a Tool is equipped?

I have a script that is supposed to change the mouse's icon when it is hovering over a certain part, let's call it Part1. Unfortunately, I don't know how I would be able to do this. Can anyone help me?

Here is what I have so far (it doesn't work by the way):

local mousee = game.Players.LocalPlayer:GetMouse()
local t = mousee.Target

local newd = coroutine.create(function()
    while wait() do
		if t.Name == "Part1" then
			mousee.Icon = "http://www.roblox.com/asset/?id=213374218"
		else
			mousee.Icon = "http://www.roblox.com/asset/?id=212856248"
		end
	end
end) --
 
coroutine.resume(newd)

The script above always makes the mouse's icon "http://www.roblox.com/asset/?id=212856248," even if the mouse is hovering over Part1.

1 answer

What you need to do is check the mouse.Target and compare it with your wanted part.

Also, if this is a tool you need to have an Equipped event.

local part = workspace.Part1 --Part to change upon

--Assuming script.Parent is the tool
script.Parent.Equipped:connect(function(mouse)
	coroutine.wrap(function()
		while wait(.5) do --.5 for reduction of client lag
			if mouse.Target == part then
				mouse.Icon = "http://www.roblox.com/asset/?id=213374218"
			else
				mouse.Icon = "http://www.roblox.com/asset/?id=212856248"
			end
		end
	end)()
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.