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)?
01 | repeat wait() until script.Parent.Loading |
02 | local max = game.ContentProvider.RequestQueueSize |
03 | print ( "Loading" ) |
04 | while game.ContentProvider.RequestQueueSize > 0 do |
05 | local progress = ((- 1 * game.ContentProvider.RequestQueueSize) + max) |
06 | local e = progress / max |
07 | print (game.ContentProvider.RequestQueueSize) |
08 | print (e .. "%" ) |
09 | wait(. 1 ) |
10 | script.Parent.Loading.Text = "Loading Assets " .. e .. "%" |
11 | end |
12 | script.Parent.Loading.Text = "Finished!" |
As @TheeDeathCaster said, you can shorten your calculation a bit. To solve the problem with "0%" you can use math.ceil
.
01 | repeat wait() until script.Parent.Loading |
02 | local provider = game:GetService( 'ContentProvider' ); |
03 | local max = provider.RequestQueueSize |
04 | print ( "Loading" ) |
05 | while provider.RequestQueueSize > 0 do |
06 | local e = math.ceil((max - provider.RequestQueueSize) / max) |
07 | print (provider.RequestQueueSize) |
08 | print (e .. "%" ) |
09 | wait(. 1 ) |
10 | script.Parent.Loading.Text = "Loading Assets " .. e .. "%" |
11 | end |
12 | 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.