Fix Player Clone Trail Slowing Down Game

Hi!

I want to have the “Sandevistan” effect from the new Cyberpunk Show (see gif for example)
GIF of Sandevistan

This is the code I have right now:

local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local UIS = game:GetService('UserInputService')
local keybind = Enum.KeyCode.Z
local debounce = false

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
character.Archivable = true

function CreateClone(plrChar, folder)
	plrChar.Parent = folder
	plrChar.PrimaryPart.CFrame *= CFrame.new(0,0,2)

	for i,v in pairs(plrChar:GetDescendants()) do
		if v:IsA("Part") or v:IsA("MeshPart") then
			v.Material = Enum.Material.Glass
			v.CanCollide = false
			v.Anchored = true
			v.Color = Color3.fromRGB(85, 255, 127)
			TweenService:Create(v,TweenInfo.new(),{Color = Color3.fromRGB(255, 0, 0)}):Play()
		end
	end
	
	--task.wait(0.1)
	--plrChar:Destroy()
end




UIS.InputBegan:Connect(function(input, istyping)
	if istyping then return end
	if input.KeyCode == keybind and player.Character.Humanoid.MoveDirection ~= Vector3.new(0,0,0) and debounce == false then
		debounce = true
		local rtp = Instance.new('Folder',character)
		for i = 1, 4 do
			task.wait(0.1)
			CreateClone(character:Clone(), rtp)
		end
		wait(3)
		rtp:Destroy()
		debounce = false
	end
end)

Example:
Gyazo GIF of example

The problem is that it slows the game down by a lot(Notice the FPS on the top left of the example footage); I want to have the same effect with the color and “trail” but without the drawback of slowing down the game.

Is this possible? If so what methods can I use to achieve this.

2 Likes

you could use viewport frames and just align them with the character

2 Likes

After some analysis, optimizing and improving the lines of code, I could see that one of the main problems was where I was saving the clones.

I hope these lines of code will work for you :smiley:

local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local UIS = game:GetService('UserInputService')
local keybind = Enum.KeyCode.C
local debounce = false

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

function CreateClone(plrChar, folder)
	plrChar.Parent = folder
	--plrChar.PrimaryPart.CFrame *= CFrame.new(0,0,2)
	plrChar.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	plrChar.Humanoid.AutomaticScalingEnabled = false
	
	local Highligtht = Instance.new("Highlight", plrChar)
	Highligtht.FillTransparency = 0.5
	Highligtht.OutlineTransparency = 1
	Highligtht.FillColor = Color3.fromRGB(0, 25, 255)
	
	TweenService:Create(Highligtht,TweenInfo.new(1),{FillColor = Color3.fromRGB(244, 255, 19)}):Play()
	
	coroutine.wrap(function()
		
		for _, v in pairs(plrChar:GetDescendants()) do
			if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("BasePart") and v.Parent == plrChar then
				v.CanCollide = false
				print(v.CanCollide)
				v.Anchored = true
				--v.Color = Color3.fromRGB(0, 25, 255)
				--TweenService:Create(v,TweenInfo.new(),{Color = Color3.fromRGB(244, 255, 19)}):Play()
			end
		end
		
	end)()
	--plrChar:Destroy()
end




UIS.InputBegan:Connect(function(input, istyping)
	if istyping then return end
	if input.KeyCode == keybind and player.Character.Humanoid.MoveDirection ~= Vector3.new(0,0,0) and debounce == false then
		debounce = true
		
		local CharFolder = Instance.new('Folder', workspace)
		CharFolder.Name = "CharClone"
		player.Character.Humanoid.WalkSpeed = 40
		for i = 1, 20 do
			task.wait(0.1)
			character.Archivable = true
			CreateClone(character:Clone(), CharFolder)
			character.Archivable = false
		end
		task.wait(3)
		CharFolder:Destroy()
		player.Character.Humanoid.WalkSpeed = 16
		debounce = false
	end
end)

If you need any clarification let me know.

And above all keep in mind that those clones are only seen by the player who activated the ability.

To fix the slowing down of the game first only create one cloned character when the button is pressed then just clone that no need to reset all the character properties and then you need to set all the parents after setting or changing properties and the Effects of color change you need to use a Hue change by tick or base number change

this uses .25 hue start and adds .025 each character clone

https://gyazo.com/dda7d1ce068f423de4d97a1e2bc619b8

Excuse me, but I really liked that color gradient that you managed to do, you did it with Tween Service, right?

by doing this using fromHSV and changing the Hue

	Color3.fromHSV(HueCount, 1, 1)
	.025  -- add .025 for each

and may want to start at .25 if you want to start green like the gif

1 Like