Camera:WorldToScreenPoint() giving wrong position

This is the script i am using

	local Vector = Object.Adornee.Parent.Parent.CurrentCamera:WorldToScreenPoint(Rig.PrimaryPart.Position)
	print(Vector)
	Effect.Position = UDim2.fromScale(Vector.X , Vector.Y)
	Effect.Parent = SelfCreature.Adornee:FindFirstAncestorWhichIsA("ScreenGui")

The Rig’s PrimaryPart is the red cube.

XY obtained from WorldToScreenPoint represent pixels offset from the top left of the screen and not scale.

Use Udim2.fromOffset instead.

1 Like

To add to what @dthecoolest said it’ll work fine on one resolution but if the player minimizes the window then it won’t scale properly

To fix that you can just normalize:

(You’re gonna need a reference for the GUI itself for the resolution)

local GUI = -- path
local normalized = Vector / GUI.AbsoluteSize

Effect.Position = UDim2.fromScale(normalized.X , normalized.Y)

Excuse me for any mistakes I am on phone!

EDIT: you can also just detect whenever absolute size changes and update the variables

2 Likes

Weird cause when i print it out it always returns less than 1, and offset rounds down.

I will try this solution as soon as i can

This places the part at 0,0,0,0
The Camera is in a ViewportFrame btw in case that changes things
If i print out vector the value given is less than 1 which leads me to believe that it returns scale and not offset, at least when in a viewportframe.