Could this be made better?

To keep it simple the code makes a fade effect with gui’s.

Code
local erroed = 0 -- varible

local ScreenGui = game.StarterGui.Loading --(Screengui)

for i = 2,15 do  
	local function fire()
		local find = ScreenGui:FindFirstChild(i-1)
		if find then
			local succes,res = pcall(function()
				if find:IsA('GuiObject') then
					local clone = find:Clone()
					clone.Name = i
					clone.Parent = find.Parent
					
					local value = 255/i
					
					clone.BackgroundColor3 = Color3.fromRGB(value,value,value)
					clone.ZIndex = tonumber(clone.Name)
					
					local dividedby = 1.1
					
					local ws,wo = find.Size.Width.Scale, find.Size.Width.Offset
					local hs,ho = find.Size.Height.Scale, find.Size.Height.Offset
					
					clone.Size = UDim2.new(ws/dividedby ,wo/dividedby, hs/dividedby, ho/dividedby)
					
					local findclone = find:Clone()
					findclone:Destroy()
					findclone.Size /= 2
					local pos = findclone.Position
					
					clone.Position = pos
				end
			end)
			if succes then
				erroed = 0
				return res
			else
				if erroed ~= 2 then
					if ScreenGui:FindFirstChild(i) then
						ScreenGui:FindFirstChild(i):Destroy()
					end
					
					erroed += 1
					fire()
				else
					print('The code has been forcefully shut down')
				end
			end

		end
	end
	fire()
	task.wait(0.5)
	
end

A simple video on how it looks:

1 Like

Sure, how about this:

local frame = script.Frame

local last = nil
for i = 1, 15 do
    task.wait(0.5)
	local copy = frame:Clone()

	copy.BackgroundColor3 = Color3.fromHSV(1,0,1/i)
	copy.Parent = last and last or script.Parent

	last = copy
end

let script be a LocalScript parented to ScreenGui and frame be the initial white frame with UI corner of size 0.9, 0, 0.9, 0, position 0.5, 0, 0.5, 0 and anchorpoint 0.5, 0.5

Since you’re multiplying it by 0.9 (or dividing by 1.1 rather) that can be replaced by the frame being that factor as its size and parenting it to the prior iterations’ result, so it ends up being the proper size without the additional overhead. I chose to use HSV colors instead as you’re dealing with a monochrome gradient so the only thing that needs to be changed is its brightness value.

3 Likes