Viewportframe how to fix bug?

RobloxStudioBeta_exRFJbXFds
help pls

local chCons = {}
local char = game.Players.LocalPlayer.Character
local player = game.Players.LocalPlayer
local pgui = player:WaitForChild("PlayerGui")
local S_RS = game:GetService("RunService")
local invOpen = false
local rmouse = game.Players.LocalPlayer:GetMouse()


char.Archivable = true
local charc = char:Clone()
for _,v in pairs(charc:GetChildren()) do
	if v:IsA("Script") or v:IsA("Folder") then
		v:Destroy()
	end
end
char.Archivable = false

table.insert(chCons,char.ChildAdded:Connect(function(v)
	if not (v:IsA("Script") or v:IsA("Folder")) then
		v:Clone().Parent = charc
	end
end))

charc.Parent = pgui.MainGui.Inventory.default.Mirror.VPFrame
charc.PrimaryPart = charc.HumanoidRootPart
charc:SetPrimaryPartCFrame(CFrame.new(0,.25,0))
charc.Name = ""
charc.Humanoid.BreakJointsOnDeath = false
charc.Humanoid.NameDisplayDistance = 0
charc.HumanoidRootPart.Anchored = true

table.insert(chCons,S_RS.RenderStepped:Connect(function()
	if invOpen and pgui.MainGui.Inventory.default.Mirror.Visible then
		local apos = pgui.MainGui.Inventory.default.Mirror.VPFrame.AbsolutePosition + (pgui.MainGui.Inventory.default.Mirror.VPFrame.AbsoluteSize/2)
		local offset = Vector2.new(rmouse.X - apos.X,rmouse.Y - apos.Y)
		charc.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0,1.7,0),Vector3.new(offset.X,0,-50 + offset.Y))
		charc:SetPrimaryPartCFrame(CFrame.new(Vector3.new(0,.25,0),Vector3.new(-math.tanh(offset.X/65)*45,-offset.Y/35,-50)))
		charc.Head.CFrame = charc.HumanoidRootPart.CFrame * CFrame.new(0,1,0) * CFrame.Angles(-math.tanh(offset.Y/135)/3,0,0) * CFrame.new(0,.5,0)
	end
end))