Character rendering in surfacegui

I thought this script would work outside of screengui since it matches the current camera, but the character is not visible. Of course, I don’t want to use screengui.

local vf = script.Parent.ViewportFrame
local char = game.Players.LocalPlayer.Character
while task.wait() do
	vf .CurrentCamera = workspace.Camera
	vf :ClearAllChildren()
	for _, v in char:GetChildren() do
		if v:IsA("BasePart") then
			v:Clone().Parent = vf
		end
	end
end


surfacegui with alwaysontop

idea:

Im pretty sure you have to parent the surfacegui to playergui and then set the adornee to the part you want it on

I succeeded in rendering the character, but it looks like a CCTV. Also, the surfacegui is too flat, so I replaced it with a billboardgui.

if you want surface gui

or billboard gui

local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")

local billboard = script.Parent.Parent
local viewportFrame = billboard:WaitForChild("ViewportFrame")

local adornee = billboard.Adornee or billboard.Parent
local camera = Workspace.CurrentCamera

local worldSizeX = billboard.Size.X.Scale
local worldSizeY = billboard.Size.Y.Scale

local function updateSize()
	viewportFrame.Size = UDim2.fromOffset(camera.ViewportSize.X, camera.ViewportSize.Y)
end

camera:GetPropertyChangedSignal("ViewportSize"):Connect(updateSize)
updateSize()

local function getProjectedSize(depth)
	if depth <= 0 then return Vector2.new(0, 0) end

	local fov = camera.FieldOfView
	local viewportHeight = camera.ViewportSize.Y

	local theta = math.rad(fov) / 2
	local factor = viewportHeight / (2 * depth * math.tan(theta))

	local pxHeight = worldSizeY * factor
	local pxWidth = pxHeight * (worldSizeX / worldSizeY) -- 비율 유지

	return Vector2.new(pxWidth, pxHeight)
end

local function onRenderStep()
	if not adornee then return end

	local targetWorldPos = adornee.Position

	local relPos = camera.CFrame:PointToObjectSpace(targetWorldPos)
	local depth = -relPos.Z

	local centerPos, onScreen = camera:WorldToViewportPoint(targetWorldPos)

	local projectedSize = getProjectedSize(depth)

	local correctX = centerPos.X - (projectedSize.X * 0.5)
	local correctY = centerPos.Y - (projectedSize.Y * 0.5)

	viewportFrame.Position = UDim2.fromOffset(-correctX, -correctY)
end

RunService:BindToRenderStep("FixViewportPosition", Enum.RenderPriority.Camera.Value, onRenderStep)

It is not perfect and was made a long time ago
but to close this