New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
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 4 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 8062 Badge of Merit Moderation Voter Administrator Community Moderator
4 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