so this is my code for using viewportFrames but its suppy laggy and idk why
local viewPortFrame = script.Parent:FindFirstChild("ViewportFrame")
local char = game.Workspace.ViewPortChars[script.Parent.Name]
char.Archivable = true
for i, ModelOrCam in pairs(viewPortFrame:GetChildren()) do
if ModelOrCam:IsA("Model") or ModelOrCam:IsA("Camera") then
ModelOrCam:Destroy()
end
end
local newCamera = Instance.new("Camera")
newCamera.Parent = viewPortFrame
viewPortFrame.CurrentCamera = newCamera
local clonedChar
game:GetService("RunService").RenderStepped:Connect(function()
if clonedChar then clonedChar:Destroy() end
clonedChar = char:Clone()
local hrp = clonedChar:WaitForChild("HumanoidRootPart")
newCamera.CFrame = CFrame.new(hrp.Position + (hrp.CFrame.LookVector * 3) + Vector3.new(0,1,0) + (hrp.CFrame.RightVector * 0), hrp.Position)
--I fiddled around with the position of the camera so you get a little bit of a side on view.
clonedChar.Parent = viewPortFrame
end)
If you want to make sure the clone is always the exact same as as the character you can determine each parts CFrame relative to the HRP. With this information you may apply it to the clonedChar to get an exact replication of where it is.
local cloned
local hrpPos = sourceCharacter:FindFirstChild("HumanoidRootPart").Position
for _, bodyPart: Instance in pairs(sourceCharacter:GetChildren()) do
if not bodyPart:IsA("BasePart") then continue end
local clonedP = cloned:FindFirstChild(bodyPart.Name)
local relCF = clonedP.CFrame - hrpPos
clonedP.CFrame = relCF
end