Trouble setting an ImageLabel to the exact position of the player's mouse on screen

Hello.

I’m trying to display an image at the player mouse’s position,
which I’ve worked out fine until I ran into an issue that im unsure on how to fix.

Here you can see the UDim2 value isn't the same as the value from mouse.X and mouse.Y, so their position is slightly off.

Image from Gyazo

Code

image

mouse.X/mouse.Y seems to be using Vector2, but I have no idea how to translate this to UDim2.
Does anyone know how I’ll be able to fix this?

Thanks in advance.

you are trying to set the scale to the Pixel position try
UDim2.new(0,mse.X,0,mse.Y)

1 Like

I have tried that, it sets the position of the label completely offscreen. I divided it by 1000 to make sure the values are in a range so that they will be visible on screen.

did you try the exact code i sent, the code i sent has the values one to the right
yours was
UDim2.new((mse.X)/1000,0,(mse.Y)/1000,0)
mine was
UDim2.new(0,mse.X,0,mse.Y)

the reason your code is inaccurate is because you would want to devide X by the screen length and Y by the screen height, but those are dynamic values (not 1000)
but by setting value 2 and 4 you are setting the exact pixel to render it at, aka your mouse position

1 Like

My reply didn’t have to do with any that, my apologies.

Is there a way to get the player’s screen height and width?

??? why do you need the width and height, i mentioned that solution as thats the path you looked like you were trying to take, but my solution skips the calculations and directly places it at the mouse location
UDim2.new(0,mse.X,0,mse.Y)
instead of
UDim2.new((mse.X)/workspace.CurrentCamera.ViewportSize.X,0,(mse.Y)/workspace.CurrentCamera.ViewportSize.Y,0)

2 Likes

My bad! Messed up something on my end. I’m fairly new to working with GUIs and only just found out using AnchorPoint is vital in this as well. :sweat_smile:

Thanks for your help!

aah, i see :stuck_out_tongue:

1 Like

And then set the AnchorPoint to (0.5, 0.5) too if you want the label centered on the mouse point.

6 Likes