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!"
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.