Error As Character doesn't exist

Hello, I am scripting a ViewportFrame and I basically want the character as the model inside of it.

So basically here’s the script:

repeat
	wait()
until game:IsLoaded()

local viewportFrame = script.Parent.Inventory.Holder1.ViewportFrame

local Client = game.Players.LocalPlayer
local Char = Client.Character



local viewportCamera = Instance.new("Camera")
viewportCamera.Parent = viewportFrame
viewportCamera.Archivable = true

function UpdateFrame()
	for i,v in pairs(viewportFrame:GetChildren())do
		if v:isA("Part") or v:isA("Model") then
			v:Destroy()
		end
	end
	local VisibleChar = Char:Clone()
	VisibleChar.Parent = viewportFrame
	
	viewportFrame.CurrentCamera = viewportCamera
	viewportFrame.SelectionImageObject = VisibleChar
	
	SetUpUpdate(VisibleChar)
end

function SetUpUpdate(Object)
	Object.Position = Vector3.new(4378.354, -12.235, -2462.885)
	viewportCamera.CFrame = CFrame.new(Vector3.new(4378.354, -12.235, -2466.494), Object.Position)
end

wait(1)

UpdateFrame()

and the error line being:

viewportCamera.Parent = viewportFrame

image

Thanks in advance! :smile:

I forgot to mention, I am using a ‘StarterCharacter’ as the Character in the game.

Please copy and paste your code into a code block instead of taking a picture.

It would also be helpful to know what line 21 is.

1 Like

I just edited the post, is this any better?