Help with loading gui

I need help fixing this error.

Error:
17:33:05.678 ReplicatedFirst.LoadingS:28: attempt to get length of a Instance value - Client - LoadingS:28
17:33:05.678 Stack Begin - Studio
17:33:05.678 Script ‘ReplicatedFirst.LoadingS’, Line 28 - Studio - LoadingS:28
17:33:05.678 Stack End - Studio


local rF = game:GetService("ReplicatedFirst")
local GameName = game:GetService("MarketplaceService"):GetProductInfo(game.PlaceId).Name
local GNT  = script["BreezeV2 Engine"]:FindFirstChild("GameName")
GNT.Text = GameName 

local contentProvider = game:GetService("ContentProvider")
local tweenService = game:GetService("TweenService")
local players = game:GetService("Players")



local player = players.LocalPlayer
local pg = player.PlayerGui
local loadings = script:WaitForChild("BreezeV2 Engine")

rF:RemoveDefaultLoadingScreen()
repeat task.wait() until game:IsLoaded()



local assets = game:GetDescendants()

local clone = loadings:Clone()
clone.Parent = pg

for i = 1, #assets do
	assets = #assets[i]
	local percentage = math.round(i / assets * 100)
	contentProvider:PreloadAsync({assets[i]})
	clone.Percentage.Text = percentage.."%"
	
	if i % 5 == 0 then
		task.wait()
	end
	
	if i == #assets then 
		task.wait(1)
	end
	
	
end

You tried to get the length of the indexed value.

2 Likes

I think maybe you’re using for loops wrong. Try using a for i, v in pairs loop instead!

local clone = loadings:Clone()
clone.Parent = pg
for i, v in pairs(game:GetDescendants()) do
    -- i is the index (number), v is the instance in the list.
    local percentage = math.round((i / assets) * 100) / 100
    pcall(function()
        contentProvider:PreloadAsync({v})
    end)
    clone.Percentage.Text = percentage.."%"
    if i % 5 == 0 then
        task.wait()
    end
end

When I use your code I get this error.

  20:45:52.259  ReplicatedFirst.LoadingS:28: attempt to perform arithmetic (div) on number and table  -  Client - LoadingS:28
  20:45:52.259  Stack Begin  -  Studio
  20:45:52.259  Script 'ReplicatedFirst.LoadingS', Line 28  -  Studio - LoadingS:28
  20:45:52.259  Stack End  -  Studio```

Oh, sorry I made a mistake. Use this:

local clone = loadings:Clone()
clone.Parent = pg
for i, v in pairs(game:GetDescendants()) do
    -- i is the index (number), v is the instance in the list.
    local percentage = math.round((i / #game:GetDescendants()) * 100) / 100
    pcall(function()
        contentProvider:PreloadAsync({v})
    end)
    clone.Percentage.Text = percentage.."%"
    if i % 5 == 0 then
        task.wait()
    end
end