Game loading bar to wait for lag to end

Hi! I’m working on a game but when you join, there’s a lot of lag (probably from chunk generation/loading and lighting.) I want to include a loading bar when you join the game showing when the game finishes loading (lag ends + everything’s loaded in). So far, the game looks like this when you join:

Does anyone know if Roblox has anything I can use to check how many things are yet to load?

1 Like

Just check if the game is loaded by doing game:IsLoaded() which returns true or false and if not, wait for it to load.

if not game:IsLoaded() then
   game.Loaded:Wait()
end

Refer to the documentation below for a better explanation

why not just making an easy loading screen

first make your loading screen (obviously) and name it like this
image

Then make a localscript inside ReplicatedFIrst then put your loading screen inside

image

now let’s make a bunch of variables

local player = game:GetService("Players")
local playergui = player.LocalPlayer.PlayerGui
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local Contentprovider = game:GetService("ContentProvider")

ReplicatedFirst:RemoveDefaultLoadingScreen() -- Does what it sound like

local LoadingScreen = script.LoadingScreen:Clone()
LoadingScreen.Parent = playergui -- clone the loading screen to the player

local FrontBar = LoadingScreen.background.Back.Front -- loading bar
local Counts = LoadingScreen.background.Back.Counts -- This is the number showing how much the contentloaded / total content

local Assets = game:GetDescendants() -- Get EVERYTHING inside the game
local LoadedAssets = 0 -- Check How many thing are loaded

To preload the assets we’ll be using ContentProvider
Just loop through your entire game and load it as shrimple as that

local player = game:GetService("Players")
local playergui = player.LocalPlayer.PlayerGui
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local Contentprovider = game:GetService("ContentProvider")

ReplicatedFirst:RemoveDefaultLoadingScreen() -- Does what it sound like

local LoadingScreen = script.LoadingScreen:Clone()
LoadingScreen.Parent = playergui -- clone the loading screen to the player

local FrontBar = LoadingScreen.background.Back.Front -- loading bar
local Counts = LoadingScreen.background.Back.Counts -- This is the number showing how much the contentloaded / total content

local Assets = game:GetDescendants() -- Get EVERYTHING inside the game
local LoadedAssets = 0 -- Check How many thing are loaded

local function Update()
	Counts.Text = "[ "..LoadedAssets.." / "..#Assets.." ]" -- Update the number
	FrontBar:TweenSize(UDim2.new(LoadedAssets/#Assets,0,1,0), "Out", "Sine", 0.1, true) -- Tween the loading bar
	LoadedAssets += 1 -- Add one everytime a asset is loaded
end

for i, v in pairs(Assets) do
	Contentprovider:PreloadAsync({v})
	Update()
end

task.wait() -- wait until everything loaded then delete itself
LoadingScreen:Destroy()
script:Destroy()

Hooley a working loading screen (Don’t mind the map I just stole it from marketplace)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.