My character does not appear in a ViewPortFrame

My problem is that my character doesn’t appear where it should (in a ViewPortFrame). This problem didn’t happen before, I left Roblox Studio for a few months and when I came back the script started crashing. I made two versions, the first was very poorly optimized and difficult to understand, then it started to fail and I thought it was due to poor optimization, the second I investigated and it is a version that I suppose is more efficient than the first, but still without appear the character

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)

local ViewPortFrameInv = script.Parent.Inventario.Player:WaitForChild("ViewportFrame")
local ViewPortFramePlayer = script.Parent.Jugador.Avatar:WaitForChild("ViewportFrame")

local player = game.Players.LocalPlayer
local char =  player.Character or player.CharacterAdded:wait(1)
char.Archivable = true

local Enabled = script:WaitForChild("ViewCharacter")

local cam = Instance.new("Camera")
cam.Name = "CamCharacter"
cam.Parent = script.Parent

ViewPortFrameInv.CurrentCamera = cam
ViewPortFramePlayer.CurrentCamera = cam

local clonedChar

game:GetService("RunService").RenderStepped:Connect(function()
	if clonedChar then clonedChar:Destroy() end
	if Enabled.Value ~= 'Inventory' and Enabled.Value ~= 'Player' then return end
	clonedChar = char:Clone()
	local hrp = clonedChar:WaitForChild("HumanoidRootPart")

	for index, obj in pairs(clonedChar:GetChildren()) do
		if obj:IsA("Script") or obj:IsA("LocalScript") or obj:IsA("ModuleScript") or obj:IsA("Tool") then
			obj:Destroy()
		end
	end
	cam.CFrame = CFrame.new(hrp.Position + (hrp.CFrame.LookVector * 5), hrp.Position)
	if Enabled.Value == 'Inventory' then
		clonedChar.Parent = ViewPortFrameInv
	elseif Enabled.Value == 'Player' then
		clonedChar.Parent = ViewPortFramePlayer
	end
end)
1 Like

I have discovered that the problem is not with my script, it is with roblox itself (this is my point of view). For some reason, with the character’s jackets, the character is no longer visible in the ViewPortFrame, removing it fixes it.