How to check when a user is hovering their mouse over a part?

How do I check when a user is hovering their mouse over a certain part?

4 Likes

You could use mouse.hit

Try using mouse.Target Example:

local players = game:GetService("Players")
local plr = players.LocalPlayer

local runService = game:GetService("RunService")

local mouse = plr:GetMouse()

function ishovering(part)
    if mouse.Target == part then
        return true
    else
        return false
    end
end

runService.Heartbeat:Connect(function()
    local h = isHovering(workspace.TestPart)
end)

The isHovering function would return true if they were hovering over it. If not, it returns false. The one argument is the part

10 Likes

this uses .LocalPlayer, so would it have to be in a local script? If so, where do I put it, since local scripts don’t run in parts.

You’d put it in startergui, and refrence the part when you call the function

2 Likes

would this cause input lag or any sorts of lag of the localplayer?

i wouldn’t run it on heartbeat. if you do that, then yes. if not, probably not. i’m not really sure tbh made this code a while ago

My papi wortst is the best at scriptin u should totally listen to him

1 Like