How would you detect a player mouse hovering over an object (without a click detector) and without causing lag?

Hey Developers,

I’m basically trying to detect when a player hovers over an object on the client, without using a click detector or without causing lag. Any ideas?

All is appreciated, thanks.

Use Mouse.Target on the client. Mouse.Target returns what BasePart the mouse is hovering over. For the Vector3 of the mouse, use Mouse.Hit

local player = game.Players.LocalPlayer
local Mouse = player:GetMouse

while wait(0.1) do
    if Mouse.Target then print(Mouse.Target) end
end
1 Like

Wouldn’t a continuous loop like that cause lag?

You could go with @RFL890 approach or you could use a surfacegui with some kind of gui element and use the mouseenter and mouseleave events and you could therefore recognize if the mouse is touching it, but this would only work depending on the face. You could also use a raycasting approach.

Information Regarding the surfacegui approach can be found here :

Information Regarding the raycasting approach can be found here :

1 Like

That’s just an example. For like a gui, you could do continuous checks if the mouse is pointing at the target, and it would not lag.

1 Like

Gotcha alright. Thanks, I’m going to try both of these options. I appreciate the help.

No problem! Furthermore if you have any other questions regarding this you can message me here on devforum or just continue this post by replying with your question.

1 Like

You’re welcome. I always had problems with rays, but it might be a better solution. Hope you have luck.

Thanks. I ended up going with a surface GUI and it’s working great. Just have to make it double sided now and I’ll be all set.

how do you make it so it doesnt go as far.

Why not use a click detector?

If you’re concerned about the mouse changing to a different image when it hover over it, you can actually change that image in the properties of the click detector.

1 Like

He said “without a click detector”

He did, but it’s not uncommon people ask questions specifying something for a perceived problem which doesn’t actually exist.

It’s not improbable someone would disregard using ClickDetector for his given reason, and by asking for more details he can eliminate this possibility.

2 Likes