WorldToScreenPoint returning very small values

I can’t seem to figure out what is the problem here. Why the WorldToScreenPoint is giving me very small numbers when I am giving it a worldpoint in the middle of the screen so would expect it to give back a few hundred pixel values for X and Y on the centre of the screen.

local vector, onScreen = camera:WorldToScreenPoint(hitPosition)
local screenPointX = vector.X
local screenPointY = vector.Y

print("hitPosition: " .. tostring(hitPosition))
print("screenPointX: " .. tostring(screenPointX))
print("screenPointY: " .. tostring(screenPointY))

and the output is:
hitPosition: 58.0399475, 7.59386587, 472.34314  -- this is about on the centre of the screen where the player character hits it
screenPointX: 0.1736513376236
screenPointY: 0.0090127885341644

What am I doing wrong or not understanding here?
Please help!

I got the solution from here: https://developer.roblox.com/en-us/api-reference/function/Camera/WorldToScreenPoint
Is there another way to do this?

get the boolean and see if it on screen

Thank you @CoderHusk good suggestion.
I did not try to check that myself since I am sure the position I was feeding it is on screen as I am using that in other parts of the code.

But it is false all the time, no matter which way I am looking.
I also tried to feed it with a known world point like in the example in the developer documentation and it still is false:

local worldPoint = Vector3.new(0, 0, 0)
local vector, onScreen = camera:WorldToScreenPoint(worldPoint)

What else should I try?

No matter where the camera is oriented when the code runs I always get these exact numbers:

screenPointX: -1.054016828537
screenPointY: -0.010715961456299
screenPointZ: -283.39163208008

for

local worldPoint = Vector3.new(0, 0, 0)

Please try this in a script what it does for you:

local camera = game.workspace.CurrentCamera

local worldPoint = Vector3.new(0, 0, 0)


while true do
	
	--https://developer.roblox.com/en-us/api-reference/function/Camera/WorldToScreenPoint
	local vector, onScreen = camera:WorldToScreenPoint(worldPoint)
	--local screenPoint = Vector2.new(vector.X, vector.Y)

	local screenPointX = vector.X
	local screenPointY = vector.Y
	local screenPointZ = vector.Z

	--local depth = vector.Z

	print("onScreen: " .. tostring(onScreen))
	print("worldPoint: " .. tostring(worldPoint))
	print("screenPointX: " .. tostring(screenPointX))
	print("screenPointY: " .. tostring(screenPointY))
	print("screenPointZ: " .. tostring(screenPointZ))
	
	wait(2)
	
end

Hmm, I copied the script over to an empty project and there it says onScreen is true all the time and gives the same values all the time no matter which way I rotate the camera.

onScreen: true
worldPoint: 0, 0, 0
screenPointX: 0.59731668233871
screenPointY: 0.63737618923187
screenPointZ: 29.156604766846

I don’t get this.
I am expecting this to wok differently based on the info here: Camera | Documentation - Roblox Creator Hub

I tried the code here Need help positioning E Icon on exact position? and that one works as expected so I need to figure out what I am doing wrong.

OK, I guess this might be obvious for most but wasn’t for me.
I was doing the whole thing in a serverscript.

Now after sending the world position over to a local script and doing the
camera:WorldToScreenPoint(worldPoint) there the values it gives are perfect for positioning the GUI object.

So the solution is to do this in a localscript: Camera | Documentation - Roblox Creator Hub