WorldToScreenPoint not working properly with ViewportFrames

I’m using WorldToScreenPoint to get the position of a part within a viewportframe for customization of the model, issues are it’s not working with my fake camera.

-- setup viewport
local RunService = game:GetService("RunService")
local viewport = script.Parent.preview
local Camera = Instance.new("Camera")
Camera.Parent = viewport
Camera.CFrame = CFrame.new(Vector3.new(0,0,0))
viewport.CurrentCamera = Camera

local cacheCF = viewport.Model.UpperTorso.CFrame
viewport.Model.PrimaryPart = viewport.Model.UpperTorso
viewport.Camera.CFrame = CFrame.lookAt((viewport.Model:GetPivot() * CFrame.new(0, 0, -2)).Position, viewport.Model:GetPivot().Position)

-- position button
local parts = viewport.Model.AddonsFolder:GetChildren()

for i,v in pairs(parts) do
	local button = script.TextButton:Clone()
	button.Parent = script.Parent
	button.Name = "InteractButton_" .. tostring(v.Name)

	local vector, onScreen = viewport.CurrentCamera:WorldToScreenPoint(v.Position)
	local scaleX = vector.X / viewport.CurrentCamera.ViewportSize.X
	local scaleY = vector.Y / viewport.CurrentCamera.ViewportSize.Y
	
	button.Position = UDim2.new(scaleX, 0, scaleY, 0)
end

-- roate button
script.Parent.rotate.MouseButton1Click:Connect(function()
	local getPivot = viewport.Model:GetPivot()
	viewport.Model:PivotTo(getPivot * CFrame.Angles(0, math.rad(45), 0))
end)

I’m quite confused why it’s not working properly. Should have little red circles on these transparent parts.

1 Like