Loading GUI Buggy

Hey!
I have a Loading Gui that in this post, I am lkearning it is getting stuck at random %'s
Post: Feedback on new game in development - Help and Feedback / Cool Creations - DevForum | Roblox
Script:


local frame = script.Parent.Frame
local base = frame.Base
local bar = base.Bar
local indicator = base.Indicator
local jpg = base.Bar.ImageLabel
local queue = game.ContentProvider.RequestQueueSize
print ("loaded")
game.ReplicatedFirst:RemoveDefaultLoadingScreen()
print ("loading screen gone xdlolollolloolololol")
while wait() do
	indicator.Text = "Loading... (" .. queue .. ")" 
	bar.Size = UDim2.new(1/queue, 0, 1, 0)
	jpg.Size = UDim2.new(1/queue, 0, 1, 0)
	wait (4)
	if queue == 0 then
		print ("queue is 0, loaded")
		indicator.Text = "Assets Loaded!"
		bar.Size = UDim2.new(1, 0, 1, 0)
		jpg.Size = UDim2.new(1, 0, 1, 0)
		wait(1)
		frame:TweenPosition(UDim2.new(0, 0, 1, 0))
	end
end

Thanks for any help!

Also, this does not happen for me. Dont know why it’s only other people.

You never update the queue in your loop. If queue is greater than zero in the beginning, then print ("queue is 0, loaded") will never get reached.

image
It’s getting to it.

That’s assuming queue is equal to zero in the first place. Again, you’re not handling having queue ~= 0 in your code.

So it is the queue == 0 must be replaced with queue ~= 0 ?

No. Your logic for handling an empty queue is fine, but you’re not taking into account what happens if queue is greater than zero before entering the loop. What happens if game.ContentProvider.RequestQueueSize=5? Your loop will keep waiting, waiting, waiting, but queue is never updated, so print ("queue is 0, loaded") will never be reached.

So where is the fix here? Do I need to check the queue size in a loop?

Yeah, just update queue inside your loop.

How would that be possible? The queue is being handled by Roblox. It is in the loop to check when the queue for loading items = 0.

	if queue == 0 then

You’re only getting queue once, outside the loop. queue will only store whatever the queue size is at that moment; even if game.ContentProvider.RequestQueueSize changes later, unless you explicitly update queue again inside of your loop with queue = game.ContentProvider.RequestQueueSize then queue will never change.

while true do

queue = game.ContentProvider.RequestQueueSize

wait()

end

Would this solve it?

Everything about that snippet is less than satisfactory: while true loop, wait(), and in the context of your problem, infinitely blocking. But I digress.

If you really want me to spoonfeed you the solution, place this line of code:

queue = game.ContentProvider.RequestQueueSize

in here:

while wait() do
    --RIGHT HERE PLACE IT RIGHT HERE YES? OK? REPLACE THIS COMMENT WITH THAT LINE OF CODE
	indicator.Text = "Loading... (" .. queue .. ")" 

the while true do part was temporary, i was gonna put it in my while wait() do loop after this.

Even then your loop is never broken out of. You should avoid while true/wait() in your code; even when the loading screen is hidden, the loop that controls it is still running in the background, wasting precious CPU time. Maybe something you could look into later.

Ok. Later on in the code i added

wait (3) --let animation finish pls
script:Destroy()