How can I move a screen gui image label to constantly hover over a base part?

Hello, I have a “fakeMouse” setup like this;
image
for the code, I turn the players mouse invisible and I make the image label follow the player’s cursor. Then I raycast check to see if it hovers over a base part. That’s all done and set up however I want to tween the image labels position on to the brick to make it stay on the base part. An affect achieved by this game. If you hover over furniture it will make your cursor tween on to the center of the furniture

Use raycasting.

Every frame, raycast forwards from the center of the screen. If it hits specific objects, center the ImageLabel. If it doesn’t, put it back at the mouse position.

I did this I dont understand how to move the image label to the objects center.

Try using :GetBoundingBox on the model you’re hovering over, and use WorldToViewportPoint to return a 2D position (in pixels) on the screen based on a Vector3.

Thanks for this feedback now I have done something but It is not working did I do something wrong? Here is my code

local cf, v3 = interactedObject.Parent:GetBoundingBox()
local v3vp, isInViewport = camera:WorldToViewportPoint(v3)
image.Position = UDim2.new(v3vp.X, v3vp.Y)

interactedObject.Parent is the model

You used UDim2.new. Try using UDim2.fromOffset as it will take 2 values and assign them to the offset part of the UDim.

this still made my mouse go to {0, 413},{0, -229} which is way off screen.
heres my code;

local cf, v3 = interactedObject.Parent:GetBoundingBox()
local v3vp, isInViewport = camera:WorldToViewportPoint(v3)
image.Position = UDim2.fromOffset(v3vp.X, v3vp.Y)

Can you print v3vp and isInViewport?

If you see the video I sent in messages it shows the location of the cursor and this prints out
562.92687988281, 132.90280151367, 29.982194900513 for vp3 depending on where I place my cursor on the brick. isInViewport will print true if I look at the cursor false if I dont.

The problem has been solved this is the code now;

local cf, size = interactedObject.Parent:GetBoundingBox()
local v3vp, isInViewport = camera:WorldToViewportPoint(cf.Position)
image.Position = UDim2.fromOffset(v3vp.X, v3vp.Y)
print(cf.Position)

I used a v3 value which actually was the part’s size not the vector3 so I used cf.Position