Hello, so I have a replay system for my Football league, and it functions properly, it just has disgusting frame rate and is laggy. The replay system basically copies select parts of Workspace and pastes it into a viewport frame.
https://www.gyazo.com/8727ed1bc4c836f1be2eb74928e13d4c
What the Explorer looks like^ What the Replay Looks like v https://www.youtube.com/watch?v=Ak6jEw2wBoY&feature=youtu.be
The code (Local script triggers module script)
local plr = game.Players.LocalPlayer
local replay = require(script.Parent:WaitForChild("Replay"))
local recordingSettings = {
LiveReplay = true, -- Should a preview be shown in the replay window?
Frame = script.Parent:WaitForChild("ReplayFrame") -- What frame to render the replay to
}
local length = 15 -- Length to capture
local speed = 0.5 -- Speed of replay (0.5 is half speed)
print("Starting "..length.."s recording!")
plr.Chatted:connect(function(msg)
if msg == "/e replay" then
for i,v in pairs (game.Workspace:GetChildren()) do
if v.Name ~= "Camera" and v.ClassName == "Camera" then
v:Destroy()
end
end
script.Parent.ReplayFrame.Visible = true
local recording = replay:BeginRecording(recordingSettings) -- Start capturing a recording
wait(length) -- Wait a bit until we want to finish capturing the replay
recording:Stop() -- Stop recording the replay
print("Recording complete!")
print("Replaying at "..speed.."x speed!")
local t = tick()
recording:Replay(speed) -- Replay with a multiplier of speed
print("Finished replaying! (Took "..(tick()-t)..")")
recording:Destroy() -- Make sure to clean up any information when you're done with the replay so you don't use up extra memory.
script.Parent.ReplayFrame.Visible = false
end
end)
What the module script looks like:
local replay = {}
function replay:BeginRecording(recordingSettings)
recordingSettings = recordingSettings or {}
local frame = recordingSettings.Frame
if not frame then
error("You must provide a ViewportFrame for the replay!")
end
local recording = {}
local data = {}
data.Header = {}
data.BaseParts = {}
data.CFrames = {}
data.Header.RecordingStarted = tick()
data.Header.RecordingStopped = false
local recorderEvent
recorderEvent = game:GetService("RunService").RenderStepped:Connect(function()
local t = tick()
local instances
if recordingSettings.GetInstances then
instances = recordingSettings:GetInstances()
else
instances = workspace:GetDescendants()
end
for _, ch in ipairs(instances) do
pcall(function()
if ch:IsA("BasePart") then
local cl = data.BaseParts[ch] or (function()
local cl = ch:Clone()
for _, ch2 in ipairs(cl:GetChildren()) do
if not ch2:IsA("DataModelMesh") then
ch2:Destroy()
end
end
if recordingSettings.LiveReplay then
cl.Parent = frame
end
return cl
end)()
data.BaseParts[ch] = cl
data.CFrames[cl] = data.CFrames[cl] or {}
data.CFrames[cl][t] = ch.CFrame
cl.CFrame = ch.CFrame
elseif ch:IsA("Camera") then
local cl = data.Camera or (function()
local cam = Instance.new("Camera")
cam.Parent = frame
if recordingSettings.LiveReplay then
frame.CurrentCamera = cam
end
return cam
end)()
data.Camera = cl
data.CFrames[cl] = data.CFrames[cl] or {}
data.CFrames[cl][t] = ch.CFrame
cl.CFrame = ch.CFrame
end
end)
end
end)
function recording:Stop()
if not data.Header.RecordingStopped then
data.Header.RecordingStopped = tick()
recorderEvent:Disconnect()
end
end
function recording:Replay(speed)
local twS = game:GetService("TweenService")
speed = speed or 1
local pointer = data.Header.RecordingStarted
local cache = {}
while pointer < data.Header.RecordingStopped do
pointer = pointer + game:GetService("RunService").RenderStepped:Wait()*speed
coroutine.wrap(function()
local cframes = data.CFrames[data.Camera]
local currentCF = data.Camera.CFrame
for t, cf in pairs(cframes) do
cache[data.Camera] = cache[data.Camera] or {}
if pointer >= t and not cache[data.Camera][cf] then
cache[data.Camera][cf] = true
currentCF = cf
break
end
end
twS:Create(data.Camera, TweenInfo.new(1/60/speed), {CFrame=currentCF}):Play()
end)()
coroutine.wrap(function()
for ch, cl in pairs(data.BaseParts) do
local cframes = data.CFrames[cl]
local currentCF = cl.CFrame
for t, cf in pairs(cframes) do
cache[cl] = cache[cl] or {}
if pointer >= t and not cache[cl][cf] then
cache[cl][cf] = true
currentCF = cf
break
end
end
twS:Create(cl, TweenInfo.new(1/60/speed), {CFrame=currentCF}):Play()
end
end)()
end
end
function recording:Destroy()
data.Camera:Destroy()
data.Camera = nil
for ch, cl in pairs(data.BaseParts) do
cl:Destroy()
end
data.BaseParts = nil
data.CFrames = nil
data.Header = nil
end
return recording
end
return replay
Also wondering if there is a way I can add shirts/pants to the replay, thanks.

5 comments
I don't know how to make a replay system yet, so I looked up a tutorial and changed some stuff. Although someone did tell me that viewport frames are not meant for a lot of objects, should I use a different way and what way would that be?
Don't expect making a clone of the full workspace to be efficient, at all
So what do you expect me to make for it to be efficient
I guess I will try recording less parts
Which I cannot do sadly after I just tried. If anyone could help me or make it so that the Module script only records Characters and a part parented under Workspace