PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

RequestQueueSize

ContentProvider

int

RequestQueueSize gives the number of items in ContentProvider's request queue that are waiting to be downloaded.

Items are added to the client’s request queue when an asset is used for the first time or ContentProvider/PreloadAsync is called.

Developers are advised not to use RequestQueueSize to create loading bars. This is because the queue size can both increase and decrease over time as new assets are added and downloaded. Developers looking to display loading progress should load assets one at a time (see example below).


Code Samples


ContentProvider Loading Bar

This code sample demonstrates how ContentProvider/PreloadAsync can be used to create a simple loading bar in a game, by loading the assets one at a time.

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(0.5, 0, 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 done")