All assets loaded detection, how to achieve it?

Morning guys, so i got a question, how can i make a loading screen that when all assets are loaded the loading screen disappears and then do something? How can i detect when all assets are loaded and then do something? i know how to make a Loading GUI that for sure, but i read some topics about this but the most of the posts about loading assets are for loading bars, so can i do achieve what i wrote previously, without any loading bars? Thanks in advance!!!

There’s a post I have made a while back. Check it out and it might give you the answer.

You would need to use ContentProvider along with the built in function :PreloadAsync() which takes in an array of objects to load in game. The function yields until that object is loaded in game.

Some code I wrote up real quickly to explain

local ContentProvider = game:GetService("ContentProvider")

local AssetsLoaded = 0 --Placeholder variable for the amount of assets loaded
local AssetsToLoad = {
    --array containing the objects, I just placed in examples
    game.Workspace.Part,
    game.Workspace.Tree,
    game.ReplicatedStorage.Map
}

for _, v in ipairs(AssetsToLoad) do
    ContentProvider:PreloadAsync({v})
    --I'm placing the object that we have retrieved through the for pairs loop in the preload async
    --As I have mentioned earlier, PreloadAsync takes in an array of objects, but in this case we want to load one asset at a time so I put an array with one object.

    AssetsLoaded += 1 --Luau syntax - Adding +1 to the current value

    --Resize your Gui here
    AssetsLoadedGui.Size = UDim2.new(1/AssetsLoaded, 0, AssetsLoadedGui.Size.Y.Scale, 0)
    --Resising the gui according to the amount of assets loaded on the Gui's X Scale axis

    --If you wanted to display amount of assets to load
    AssetsLoadedLabel.Text = AssetsLoaded .. "/" .. #AssetsToLoad
    --Getting the amount of assets to load and seperating it by the amount (#) of assets there are to load in the array

    --Do some other stuff if you prefer with that object
end

--All assets have been loaded, do your something.

Edit: Looks like I have just what you need

18 Likes

Please search around for other posts on the DevForum before asking, you dont need a loading bar at all, simply remove that part of the code.

1 Like