Recording system bug

hello,

yesterday i tried making a camera system that would record what player see (like in game “action”), and it works well but there is small issue. When i tried adding so characters would appear too, it seems very lagy. Here is the camera script I made:

local UIS = game:GetService("UserInputService")

local VPF = script.Parent:WaitForChild("ViewportFrame")
local StartRecordingButton = script.Parent:WaitForChild("StartRecording")
local PlayButton = script.Parent:WaitForChild("Play")

local Video = game.ReplicatedStorage:WaitForChild("Video")
local Vid = script.Parent:WaitForChild("Vid")

local IsRecording = false
local Recorded = false
local IsPlaying = false

local fps = 50

local Objs = game.Workspace:WaitForChild("VPFObjs"):Clone()
Objs.Parent = VPF
Objs.Name = "Obj"

local function Clone(Id)
	local NewCam = VPF.CurrentCamera:Clone()
	NewCam.Name = Id
	NewCam.Parent = Video
end

local function Play()
	for i = 1, #Video:GetChildren(), 1 do			
		local Clone = Video[i]:Clone()
		
		Clone.Parent = Vid
		VPF.CurrentCamera = Clone
		
		wait(1 / fps)
		
		spawn(function()
			wait(1 / fps + 0.015)
			Clone:Destroy()
		end)
	end
	
	VPF.CurrentCamera = game.Workspace.CurrentCamera
end

local function ResetVideo()
	if not IsRecording and Recorded and not IsPlaying then
		Recorded = false
		Video:ClearAllChildren()
		PlayButton.BackgroundColor3 = Color3.fromRGB(75, 75, 75)
		StartRecordingButton.BackgroundColor3 = Color3.fromRGB(0, 180, 0)
		StartRecordingButton.Text = "Start Recoding [F]"
	end
end

local function Start_StopRecording()
	if IsRecording == false and Recorded == false then
		IsRecording = true
		StartRecordingButton.Text = "Recording..."

		spawn(function()
			local n = 1

			while IsRecording == true do
				wait(1 / fps)
				Clone(n)
				n += 1
			end

			Recorded = true
			IsRecording = false
			StartRecordingButton.Text = "Reset"
			StartRecordingButton.BackgroundColor3 = Color3.fromRGB(180, 0, 0)
			PlayButton.BackgroundColor3 = Color3.fromRGB(0, 132, 193)
		end)
	elseif IsRecording == true and Recorded == false then
		IsRecording = false
	elseif IsRecording == false and Recorded == true then
		ResetVideo()
	end
end

PlayButton.MouseButton1Click:Connect(function()
	if Recorded == true and IsPlaying == false then
		IsPlaying = true
		Play()
		wait(0.1)
		IsPlaying = false
	end
end)

StartRecordingButton.MouseButton1Click:Connect(Start_StopRecording)

UIS.InputBegan:Connect(function(key, GameAction)
	if not GameAction then
		if key.KeyCode == Enum.KeyCode.F then
			Start_StopRecording()
		end
	end
end)

VPF.CurrentCamera = game.Workspace.CurrentCamera

while wait(1 / fps) do
	local PlayersFolder = game.Workspace:WaitForChild("Players"):Clone()
	PlayersFolder.Parent = VPF
	
	spawn(function()
		wait(1 / fps + 0.015)
		PlayersFolder:Destroy()
	end)
end

I dont know if thats how you make a camera system but thats the only way i image it would work. Here is what happens when i tried adding player character:

robloxapp-20230213-1604205.wmv (1,7 MB)

let me know if you have any idea how to fix this issue (maybe i’m doing this system wrong).