Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Intro loading assets GUI?

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

✓ Accepted answer

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!

1 comment

0

Wow just 9 lines of codes!! Thanks alot, it has worked :D

This discussion is preserved as it was. New answers, comments, and votes are closed.