So I basically want to create a ghost trail behind the player (Kinda like ZO but with color) and I wrote this:
local OGAgent = game.Workspace.Agent -- Character Model
local FADE_TIME = 1.5
local ONION_LAYERS_FOLDER = game.Workspace.OnionLayers
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local Debris = game:GetService("Debris")
local tweenInfo = TweenInfo.new(FADE_TIME, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local tweenGoal = {}
tweenGoal.Transparency = 1
wait(1)
local connection = RunService.Heartbeat:Connect(function(deltaTime)
local newLayer = OGAgent:Clone()
newLayer.Parent = ONION_LAYERS_FOLDER
for i, child in pairs(newLayer:GetDescendants()) do
if child:IsA("BasePart") or child:IsA("Decal") then
TweenService:Create(child, tweenInfo, tweenGoal):Play()
end
end
Debris:addItem(newLayer, FADE_TIME)
end)
but it’s creating a lot of lag, how could I optimize this (and is cloning models really expensive)?