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

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

Asked by 10 years ago

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

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

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)
Ad

Answer this question