Context
I have made a simple replay system where while your playing a level, it records the position of your character every 0.1 seconds to a table, and then the next time you play that same level it creates a ghost (its just a blue part right now) that replays your character from the last attempt you made.
The Goal
It works great right now, but I wanted to also be able to show the replays of all players currently in the game, as I believe many new players that want help winning would want to see where the majority of players go during a level, which would give them useful information to compare and change their play styles.
The Code
Here is a general code example of how my local script renders these replays, im not showing the full code as I believe its un-needed to answer my simple question
local function replay()
local Dummy = Instance.new("Part")
Dummy.Name = game.Players.LocalPlayer.Name.."-[Practice Ghost]"
Dummy.Size = Vector3.new(3,2,3)
Dummy.Color = Color3.new(0, 0.984314, 1)
Dummy.Transparency = 0.8
Dummy.Anchored = true
--
local video = replaySTORAGE.LatestReplay.Video
-- Note, positions are stored in tables {x,y,z} because datastores cant save Vector3's
Dummy.Position = Vector3.new(video[1][1],1.5,video[1][3]) or Vector3.new(51.5,1.5,59.5)
Dummy.Parent = workspace
--
local function start()
local newPos = nil
--warn("replay has started")
task.spawn(function()
for frameNumber, position in video do
newPos = Vector3.new(position[1],position[2],position[3])
if newPos ~= Dummy.Position then -- no need to tween if its the same position as previous
-- Tween the part to the new position!!!!!!!!!!!!
end
task.wait(0.1)
end
--warn("replay has ended")
end)
end
start()
end)
end
The Question
Right now I only replay the local players replays with 1 task.spawn and 1 for loop, but I wish to replay multiple replays from all players (max 25 replays), so the question is…
Should I keep 1 thread and have a giant for loop that renders every replay every 0.1 seconds, or should I make a thread for each replay instead? I want the most efficient way to give the best performance as this is running on a local script.