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

My Loading Assets Screen Is Inefficient?

I am trying to make a loading screen which displays the assets loaded percentage but I feel like there is a way to shorten this, and sometimes it doesnt work (print)?

repeat wait() until script.Parent.Loading
local max = game.ContentProvider.RequestQueueSize
print("Loading")
while game.ContentProvider.RequestQueueSize > 0 do
	local progress = ((-1 * game.ContentProvider.RequestQueueSize) + max)
	local e = progress / max
	print(game.ContentProvider.RequestQueueSize)
	print(e .. "%")
	wait(.1)
	script.Parent.Loading.Text = "Loading Assets " .. e .. "%"
end
script.Parent.Loading.Text = "Finished!"

2 comments

0

It keeps printing 0% at print(e .. %)

0

Why the need to do all those calculations? e-e Why not just (All - Current) / All, or something like that for the calculations?

1 answer

As @TheeDeathCaster said, you can shorten your calculation a bit. To solve the problem with "0%" you can use math.ceil.

repeat wait() until script.Parent.Loading
local provider = game:GetService('ContentProvider');
local max = provider.RequestQueueSize
print("Loading")
while provider.RequestQueueSize > 0 do
    local e = math.ceil((max - provider.RequestQueueSize) / max)
    print(provider.RequestQueueSize)
    print(e .. "%")
    wait(.1)
    script.Parent.Loading.Text = "Loading Assets " .. e .. "%"
end
script.Parent.Loading.Text = "Finished!"

It should work fine, but if it doesn't, you can also use the new math.clamp function to clamp it between 1 and 100.

Hope this helped.

1 comment

0

Wouldn't line 1 cause a problem? It's set to directly get the object and not check. Also, I checked out line 6; when I tested it out of curiosity, it only returned 1 & 0. Was this intentional?

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