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

Intro loading assets GUI?

Asked by
snewo12 72
6 years ago

Hello,

So I have a script that is working well (asked for help):

local workspaceassets = game.Workspace:GetChildren()
local replcatedastorageassets = game.ReplicatedStorage:GetChildren()
local startguiassets = game.StarterGui:GetChildren()


local numberofassets = #workspaceassets + #replcatedastorageassets + #startguiassets

while wait() do
    for x = numberofassets,0,-1 do
        wait(0.5)
        script.Parent.Text = "Loading assets...: "..x.."/"..numberofassets 
    end
    script.Parent.Text = "Game loaded!"
    wait(2)
    script.Parent.Text = "Enjoy the game!"
    wait(2)
    script.Parent.Visible = false
    script.Parent.Parent.Parent:Destroy()
end

The only thing is: It actually loads stuff that has been loaded too, so it's doing everything one by one. Is there also one that doesn't load stuff that has already been loaded? And if there is a solution, how do I script that (I'm just a beginner :/)?

Thanks in advance :)

1 answer

Log in to vote
2
Answered by
ee0w 458 Moderation Voter
6 years ago
Edited 6 years ago

Don't do that. Use the ContentProvider service using the GetService method. It's very simple to use!

-- Local or Server script

local cp = game:GetService("ContentProvider")
while cp.RequestQueueSize > 0 do
    print(cp.RequestQueueSize) -- Prints the amount of assets in queue (to load).
    wait()
end

To make a loading GUI, just get the RequestQueueSize at the beginning of the script, then compare it to the new queue, which should give you a rough estimate.

Ex:

local cp = game:GetService("ContentProvider")
local totalassets = cp.RequestQueueSize -- Saves the amount of assets at the current moment (to compare to later)

while cp.RequestQueueSize > 0 do
    print(cp.RequestQueueSize .. " left of " .. totalassets .. " assets remaining...")
    wait()
end

print("All assets loaded!")

Hope I helped!

0
Wow just 9 lines of codes!! Thanks alot, it has worked :D snewo12 72 — 6y
Ad

Answer this question