Timeskip Effect Optimization

I want to achieve a similar timeskip effect to this. https://www.youtube.com/watch?v=L7LY73HvzEE
my game: https://streamable.com/433wq6

I’ve gotten pretty close except that the game freezes for a second or two. It’s obviously because I’m getting so many parts at once but is there a way to optimize this?

I’ve tried adding some kind of wait but it looks ugly with it.

My Code:

-- Here's my client code (and yes it is supposed to be run on the client.)

local Cooldown = false
local TweenService = game:GetService("TweenService")

local TimeskipObjectsTable = {}

local TimeskipOriginObjectsObject = {}
local TimeskipOriginObjectsSize = {}

local MapHitbox = Instance.new("Folder")
MapHitbox.Name = "MapHitbox"
MapHitbox.Parent = workspace

for i,v in pairs(workspace:GetDescendants()) do
	if v:IsA("BasePart") and v.Name ~= "Terrain" then
		for i2,player in pairs(game.Players:GetPlayers()) do
			if v:IsDescendantOf(player.Character) then
				return
			end
		end

		table.insert(TimeskipOriginObjectsObject,v)
		table.insert(TimeskipOriginObjectsSize,v.Size)
		
		local HitBox = v:Clone()
		HitBox.Parent = MapHitbox
		HitBox.Transparency = 1
		HitBox.Name = HitBox.Name.."Clone"

		table.insert(TimeskipObjectsTable,HitBox)
	end
end

local function CrumbleTheEarth()
	for i,v in pairs(workspace:GetDescendants()) do
		if v:IsA("BasePart") and v.Name ~= "Terrain" then
			for i2,player in pairs(game.Players:GetPlayers()) do
				if v:IsDescendantOf(player.Character) then
					return
				end
			end
			
			TweenService:Create(v,TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.InOut),{Size = Vector3.new(0,0,0)}):Play()
		end
	end
end

local function FixTheEarth()
	for i,v in pairs(TimeskipOriginObjectsObject) do
		v.Size = TimeskipOriginObjectsSize[i]
	end
end

local TimeSkipDuration = 10

game:GetService("UserInputService").InputBegan:Connect(function(Key)
	if Cooldown then return end
	if Key.KeyCode == Enum.KeyCode.E then
		Cooldown = true
		
		game.SoundService:PlayLocalSound(game.SoundService.Start)
		
		wait(1)
		
		CrumbleTheEarth()
		
		local imagelabel = Instance.new("ImageLabel")
		imagelabel.Parent = script.Parent
		imagelabel.Size = UDim2.new(3,0,5,0)
		imagelabel.Image = "http://www.roblox.com/asset/?id=6000771604"
		imagelabel.BackgroundTransparency = 1
		imagelabel.ZIndex = 69
		
		for y = 1,5 do
			for x = 0,2 do
				imagelabel.Position = UDim2.new(-x,0,-y,0)
				wait(0.05)
			end
		end
		
		imagelabel:Destroy()
		
		game.ReplicatedStorage.KingCrimsonSpace:Clone().Parent = game.Lighting
		game.SoundService.Theme:Play()
		
		wait(TimeSkipDuration)
		
		game.SoundService:PlayLocalSound(game.SoundService.Resume)
		
		local imagelabel = Instance.new("ImageLabel")
		imagelabel.Parent = script.Parent
		imagelabel.Size = UDim2.new(3,0,5,0)
		imagelabel.Image = "rbxassetid://5999376560"
		imagelabel.BackgroundTransparency = 1
		imagelabel.ZIndex = 69
		
		for y = 1,5 do
			for x = 0,2 do
				imagelabel.Position = UDim2.new(-x,0,-y,0)
				wait(0.05)
			end
		end
		
		game.SoundService.Theme:Stop()
		FixTheEarth()
		
		game.Lighting:FindFirstChild("KingCrimsonSpace"):Destroy()
		
		wait(1)
		
		Cooldown = false
	end
end)

If anyone could help that would be great!

Perhaps look into viewport frames. What you can do, is create a viewport frame on a GUI (covering the real world) create a copy of the world 100 blocks in each direction, and just clone them into the viewport, then you can animate that. Just delete the frame after, and you have returned to the “real world”

2 Likes