Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Loading Gui that actually loads stuff?

Asked by 8 years ago

Please do not link wiki pages and try to explain to the best you can. I found this on wiki and was wondering how it worked.

local ContentProvider = Game:GetService("ContentProvider")

local function WaitForAssetsToLoad()
    -- Yields until all requested assets are loaded.

    while (ContentProvider.RequestQueueSize > 0) do
        wait()
    end
end

1 answer

Log in to vote
14
Answered by 8 years ago

Before I can explain what RequestQueueSize is, I need to explain how ROBLOX loads assets. Unlike normal games whose textures, sounds, and meshes are installed when you install the game, you don't have ROBLOX game assets installed on your computer. It wouldn't be feasible to install every asset ever uploaded to ROBLOX to your computer, so what ROBLOX does is they download assets on a need-to-know basis. When you first join a game, ROBLOX starts to download all assets the client knows of. All meshes, decals, etc in the workspace and ReplicatedStorage will be downloaded. Then, if you insert an asset into the game with unloaded decals later down the road, its decals will be downloaded too. ROBLOX can't download all of these simultaneously, so they use a queue. They put items into this queue and each item is downloaded one by one. RequestQueueSize tells you how many items are in that queue. If there are 0, that means the client isn't downloading anything -- it's finished.

However, that is not the best way to load assets. If you wait until the queue size is 0, that means that if you have an entire place loading, but only want to load the intro screen image / audio before playing the intro, you'll have to wait for the entire place to load instead of just those two assets which will take ages longer and your players will be sitting there at your loading screen doing nothing. Nobody likes loading screens -- you should only preload essential assets that break the game if not loaded. The best way to load essential assets like that is with PreloadAsync, also a member of ContentProvider, which was recently implemented:

http://wiki.roblox.com/index.php?title=API:Class/ContentProvider/PreloadAsync

If you call that for each of your essential assets, your script will pause (yield) until those assets have finished loading.

0
Very through and well thought answer, +1! User#5978 25 — 8y
Ad

Answer this question