Detecting the surface gui object the mouse is hovering over

How would I go about detecting a frame inside a surfacegui that the mouse is hovering over similar to mouse.Target?

Whilst there’s no built in method that I know of you could probably use some maths to calculate the position of the cursor on the part

I’m aware of that, I am not sure about how to go about the math part though. My surfacegui is exactly 128x128 pixels and each frame is 1x1 pixel. I was thinking of somehow using the position of the mouse to compare it to the position & size of the canvas to know exactly the pixel coordination that the mouse is hovering hover but I am not sure how I would go about that, maybe raycasting?

https://developer.roblox.com/en-us/api-reference/function/BasePlayerGui/GetGuiObjectsAtPosition

Already tried this method, upon using it, it returned an empty table I don’t think it works with SurfaceGuis or alternatively I have used it wrong.

I just realized you were working with SurfaceGuis, that method is exclusively for ScreenGuis.

Can you not just use MouseEnter/MouseLeave? Parent the SurfaceGui to the StarterGui folder and set its ‘Adornee’ property to the part you want it to be cast from.

I cannot use MouseEnter and MouseLeave because besides the fact that it is not that accurate it is too performance consuming and inefficient for my use. I’m aware I could set its adornee property to the part but it is a surfacegui that the all players will be able to modify and I think it would be too heavy on the server and clients to receive a constant stream of updates each time it is modified.

Client input on SurfaceGuis/BillboardGuis is handled by the client and thus is only replicated to that client.

Additionally, MouseEnter/MouseLeave events can be handled by the client too (via a local script).

I am aware of that, but if the client would make a change to the surface gui, a remote event would have to be fired and then the server would have to fire all the clients so the surface gui would be updated for everyone which I think is too straining. Also as I said MouseEnter and MouseLeave isn’t really an option.

That is going to be required anyway, client input on SurfaceGuis/BillboardGuis is only going to be replicated for that particular client (hovering over a button, scrolling a scroll bar etc.).

It is less performance consuming because the server is just replicating changes to the clients instead of the client having to do the changes by itself.