Loading screen with % not functioning

I have a loading screen UI that shows the percentage o the assets loaded in the game, the issue is the % doesn’t update and stays at 0% although through the output I can see assets being loaded. How can I go on about this?

local PlayerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
local ui = script.Loading:Clone()
ui.Parent = PlayerGui
local CP = game:GetService("ContentProvider")
repeat ui:WaitForChild("K"):WaitForChild("TextLabel").Text = math.floor(((CP.RequestQueueSize-CP.RequestQueueSize)/CP.RequestQueueSize)* 100)..'%' ui:WaitForChild("dis"):TweenSize(UDim2.new(0.6 - string.format('%.3f',CP.RequestQueueSize/CP.RequestQueueSize),0,0.243,0),1,0,.5,true) wait(1) until 
CP.RequestQueueSize <= 0
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, true)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList, true)
1 Like

I am assuming it’s the math.floor part and it’s I
not in the correct place. I am sorry if I am wrong.

If it’s not in the correct place, where could it possibly be?

math.floor((CP.RequestQueueSize-CP.RequestQueueSize)/CP.RequestQueueSize)* 100

Try this

Sorry I am on phone.

Still had the same result as before.

Wait a minute,


Would this just be 0 right?
As it’s the same value.

Yeah I found your problem, of course this would be 0.

Oh, I didn’t notice that what would I change it out to…

Yeah I don’t really know,
(100 - CP.RequestQueueSize)

Just mess around with the numbers, or someone else may know. Good luck!

Ok, I got it to work except I need to find a perfect number to replace the 100 with so the percentage stays between 0-100.

just clamp the percentage between 0 and 100

local p = 110
p = math.clamp(p, 0, 100)

before displaying it


Wherever you’re displaying the value,

 -- assume v is the value you need to display
 -- instead of doing something.Text = v, do

 something.Text = math.clamp(v, 0, 100).. " %"

How would I imply that to my script?

(Sorry, never heard of .clamp)

math.clamp is not the right answer, it will mess up the percentage.
You need to record the queue size at the top and compare against that.

local totalQueue = CP.RequestQueueSize

And then to set the percentage

local tl = ui:WaitForChild("K"):WaitForChild("TextLabel")
   local percent = math.floor((1-CP.RequestQueueSize/totalQueue)*100)
   -- blah blah
until CP.RequestQueueSize <= 0

Hm, I get -inf when I run that line of code.

Show me where you set the totalQueue variable. I wonder if RequestQueueSize starts at 0.
I just tested it, and so long as totalQueue is greater than zero and CP.RequestQueueSize is less than totalQueue, it works.

The script is exactly like this:

local totalQueue = CP.RequestQueueSize

   local percent = math.floor((1-CP.RequestQueueSize/totalQueue)*100)
ui:WaitForChild("K"):WaitForChild("TextLabel").Text = percent
until CP.RequestQueueSize <= 0

I re-wrote the WaitForChild line for a reason, you shouldn’t be calling WaitForChild more than once, it’s a lot of inefficiency. That’s not going to fix anything, I’m just letting you know.

Try throwing a wait at the top, somewhere between one and five seconds, see if that fixes anything.

local totalQueue = 65536
local leftToLoad = 10000
print(math.floor((1-leftToLoad/totalQueue)*100)) --> 84

Same result as before, except when it completes loading the TextLabel’s Text is “-nan(ind)”