yooo, could someone help me on how to make my viewportframe better because this is my code right now (I wan’t to animate it)
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 * 2.5) + Vector3.new(0,1,0) + (hrp.CFrame.RightVector * 0), hrp.Position)
clonedChar.Parent = viewPortFrame
end)
but because I cloning it all the time and spawning it in again its lagging way to much but idk how to make it better. could anyone help me?