--// Gather instances/parts

for _, instance in pairs (workspace.Lobby:GetDescendants()) do
	if instance:IsA("BasePart") then
		
	end
end

spawn(function()
	cp:PreloadAsync(ia)
	loaded = true
end)

local total = #ia
local assetLoaded = {}

function checkLoaded(asset)
	if asset:IsA("Sound") then
		return assetLoaded[asset.SoundId]
	else
		return assetLoaded[asset.Image]
	end
end

local was = 0
while not loaded do
	local t = 0
	for _, asset in pairs (hud:GetDescendants()) do
		if (asset:IsA("ImageButton") or asset:IsA("ImageLabel") or asset:IsA("Sound")) and not checkLoaded(asset) and asset.isLoaded then
			if asset:IsA("Sound") then
				assetLoaded[asset.SoundId] = true
			else
				assetLoaded[asset.Image] = true
			end
			t = t + 1
		end
	end
	if t > was then
		bg:TweenSize(UDim2.new(1, 0, bg.Position.Y.Scale - (t / 100), 32), "Out", "Linear", 0.15)
		was = t
	end
	warn (t, "out of", total, "assets loaded!")
	if t >= total then
		loaded = true
		break
	end
	wait(0.5)
end
if loaded then
	warn "LOADING COMPLETE"
	bg:TweenSize(UDim2.new(1, 0, 0, 0), "Out", 'Linear', 0.15)
	hud.HUDEngine.Doing.LoadingIngame.Value = false
end
