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

How do i add the Loading GUI That actually loads assets?

Asked by 7 years ago

How do i add the Loading GUI That actually loads assets like Murder Mystery 2 who have the LOADING GUI That actually loads assets?

3 answers

Log in to vote
3
Answered by
DanzLua 2879 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

Well we can use the contenprovider service to help us get a number of how many assets are remaining.

Make a new local script and put it inside startergui, Lets setup our variables inside the script, Im assuming that inside startergui you have a screengui named "ScreenGui" inside which you have a Frame named "Frame" and a TextLabel named "TextLabel",

local gui = script.Parent.ScreenGui --change this if you need to
local text = gui.Frame.TextLabel --change this if you need to

Lets setup our variable for the service

local cp = Game:GetService("ContentProvider")

We can find how many assets are left to load by getting RequestQueueSize of the service.

We want it so that while the RequestQueueSize is still more than 0 then we want to show how many assets are left in our text label

while cp.RequestQueueSize > 0 do
    text.Text="Assets Remaining: "..cp.RequestQueueSize..""
    wait(.5)
end

Lets put everything together,

local gui = script.Parent.ScreenGui --change this if you need to
local text = gui.Frame.TextLabel --change this if you need to

local cp = Game:GetService("ContentProvider")

while cp.RequestQueueSize > 0 do
    text.Text="Assets Remaining: "..cp.RequestQueueSize..""
    wait(.5)
end

We can also add assets we want to load in by using :Preload() of the service

local assets = {2253543, 2434541, 5133543, 2423433} --Ids to load
for _, asset in ipairs(assets) do
    cp:Preload("http://www.roblox.com/asset/?id=" .. asset)
end

^ they created a table will ids inside and then made a loop to add each id to the assets to preload.

Lets add this to our complete script,

local gui = script.Parent.ScreenGui --change this if you need to
local text = gui.Frame.TextLabel --change this if you need to

local cp = Game:GetService("ContentProvider")

local assets = {2253543, 2434541, 5133543, 2423433} --Ids to load
for _, asset in ipairs(assets) do
    cp:Preload("http://www.roblox.com/asset/?id=" .. asset)
end

while cp.RequestQueueSize > 0 do
    text.Text="Assets Remaining: "..cp.RequestQueueSize..""
    wait(.5)
end

But if you reset the startergui will be reset and this this will replay so lets prevent this from happening, Inside StarterGui there is a bool called ResetPlayerGuiOnSpawn, Turn that off and it won't reset :)

If you have any questions please ask me, Hope you found this useful :D

Source

Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

The ContentProvider service

local cp = game:GetService("ContentProvider")

local partsToLoad = cp.RequestQueueSize

while cp.RequestQueueSize > 0 do
    wait(1)
    print("Loaded "..partsToLoad-cp.RequestQueueSize.." out of "..partsToLoad)
end
0
Use this as you wish. And if I helped, please press "Accept Answer". TheHospitalDev 1134 — 7y
0
You did not help cheslin23t 4 — 3y
Log in to vote
0
Answered by
sad_eyez 162
7 years ago
Edited 7 years ago

This is one way i found to do it, Even though the one above is more efficient.

--[[This should be a local script inside the textlabel that will show the assets loading]]--


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

local numberofassets = #workspaceassets + #replcatedastorageassets + #serverscriptserviceassets + #startguiassets

while wait() do
    for x = numberofassets,0,-1 do
        wait(0.5)
        script.Parent.Text = "Assets Left To Load: "..x
    end
    script.Parent.Text = "All "..numberofassets.." Have Been Loaded!"
    wait(1)
    script.Parent.Visible = false
    script.Parent.Parent.Parent:Destroy()
end

Answer this question