Loading game as assets

Hello,

I would like to know how do I script to load assets in-game. I mean, when you join any game it takes long to be loaded so I want to script a loading assets until it’s fully loaded by reaching to 0 assets and saying “Loading complete!” or any texts I want. xD

Thank you.
Peterboy_RBLX

1 Like

You can use ContentProvider’s request queue size to get how many assets are loading.
Once it gets to below a certain amount or gets to 0 (your choice here), you can finish the loading bar.
There’s more information here, including an example of a loading bar!

Wait, but it doesn’t tell me where to put that script.

So, with this script I would like to know if it’s on a local script or just “script” and where do I put.

Since it uses LocalPlayer, it has to be a LocalScript. This code it gives you creates the loading bar etc.
Just put the code in a LocalScript in StarterGui preferably.

Okay, some scripts even LocalPlayer sometimes might not be local script but thanks anyways. xD

Scripts run on the server and cannot use the LocalPlayer. The LocalPlayer is the client who the LocalScript is running for. I don’t see how those Scripts used the LocalPlayer :thinking:

:thinking: Okay.

When I tested in-game it just appeared a tiny Screen GUI and I want to make it whole of screen then should disappear when loading is complete.

Edit what Frame.Size/Frame.Position is. 1,0,1,0 should fill the entire screen.

Something that shows me is frame.Size = UDim2.new(0.0, 0, 0.1, 0)

What should I do? Even with “.”

Just set it to frame.Size = UDim2.new(1,0,1,0)

Ok, now it’s whole screen.

So, in-game it appears grey then blue.

local ContentProvider = game:GetService(“ContentProvider”)
local Players = game:GetService(“Players”)

– create a screenGui
local localPlayer = Players.LocalPlayer
local playerGui = localPlayer:WaitForChild(“PlayerGui”)
local screenGui = Instance.new(“ScreenGui”, playerGui)

– create a basic loading bar
local frame = Instance.new(“Frame”, screenGui)
frame.Size = UDim2.new(1,0,1,0)
frame.Position = UDim2.new(0.5, 0, 0.5, 0)
frame.AnchorPoint = Vector2.new(0.5, 0.5)

local bar = Instance.new(“Frame”, frame)
bar.Size = UDim2.new(0, 0, 1, 0)
bar.Position = UDim2.new(0, 0, 0, 0)
bar.BackgroundColor3 = Color3.new(0, 0, 1)

– create some sample assets
local sound = Instance.new(“Sound”)
sound.SoundId = “rbxassetid://301964312”
local sound2 = Instance.new(“Sound”)
sound2.SoundId = “rbxassetid://301964312”

– create a table of assets to be loaded
local assets = {
sound,
sound2
}

wait(3)

for i = 1, #assets do
local asset = assets[i]
ContentProvider:PreloadAsync({asset}) – 1 at a time, yields
local progress = i / #assets
bar.Size = UDim2.new(progress, 0, 1, 0)
end

print(“Loading complete!”)

So, I would like it to appear texts of loading assets with numbers but background of GUI should be as grey or almost black.

Well, to change the frame’s color you can do something like:

frame.BackgroundColor3 = Color3.fromRGB(r, g, b) --YOU NEED TO SET THESE

And for the Text you can create a TextLabel then have it’s text set. I’d have it like:

TextLabel.Text = string.format("Loading! Assets to load: %d", ContentProvider.RequestQueueSize)

Actually, I made a screen GUI then label assets loading but I would like it to have numbers then countdowning until it’s loaded.

Well you could use a while loop so while the RequestQueueSize is not 0 then show the text I shown.
After the while loop make the UI invisible or do what you want to get rid of the UI.

Sorry may you show me the script? I still don’t get it. xD

So something like (I changed my idea on the while loop):

local cp = game:GetService("ContentProvider")
local c 
script.Parent.Text = string.format("Loading! Assets to load: %d", cp.RequestQueueSize)

c = cp:GetPropertyChangedSignal("RequestQueueSize"):Connect(function()
    if cp.RequestQueueSize == 0 then
        c:Disconnect()
        script.Parent.Text = "Fully loaded!"
        --Do the finished loading stuff here
    else
        script.Parent.Text = string.format("Loading! Assets to load: %d", cp.RequestQueueSize)
    end
end)

Not working, but I did put that script like that. Screenshot by Lightshot

It needs to be a LocalScript inside the TextLabel.

You can use InsertService safely if you are loading in assets by you or Roblox.

How do I do it? I’m not good scripter yet, it’s quite hard to learn. xD

1 Like