Loading screen process bar not working

  1. What do you want to achieve? I want the loading screen’s process bar to start moving

  2. What is the issue? The loading screen’s process bar is not working at all. It’s either that the formula is wrong (but I’ve used the same formula for all my other bar scripts and they’ve worked perfectly) or just some other issue.

  3. What solutions have you tried so far? I tried multiplying instead of adding but that tweened the GUI bigger in the Y axis. I also tried to put 1 as the Y scale, which is the size of the fill bar on the Y axis.

I’ve also tried using task.spawn() instead of just calling the function

local Assets = game:GetDescendants()

for count, asset in pairs(Assets) do
	ContentProvider:PreloadAsync(
		{asset},
		function()
			GUI.Contents.Lower.AssetsLoaded.Text = "Assets loaded: "..count
			local Formula = UDim2.fromScale(count / #Assets + OldXScale, FillBar.Size.Y.Scale)
			local BarTween = TweenService:Create(FillBar, TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Size = Formula})
			BarTween:Play()
			
		end
	)
end
2 Likes

Does the AssetsLoaded text get updated? Is the issue in the bar itself or is the entire script flawed? Is the bar not moving at all or just doing it wrong?

It’s not moving at all. The AssetsLoaded text gets updated, yes. The issue is only in the bar.

I myself would put the things you have in the callback function after the ContentProvider:PreloadAsync() function.
Also, I’m not sure if it’s a good idea to tween for every single asset like that. The next tween will have started before the previous one finishes. Try just setting the bar’s size instead of tweening. It would look something like this:

local Assets = game:GetDescendants()

for count, asset in pairs(Assets) do
	ContentProvider:PreloadAsync({asset})

    GUI.Contents.Lower.AssetsLoaded.Text = "Assets loaded: "..count
	local Formula = UDim2.fromScale(count / #Assets + OldXScale, FillBar.Size.Y.Scale)
	FillBar.Size = Formula 
end
1 Like

It will not be smooth if I just add to the size.

So I did what you said and it’s still not working. Seems like the problem is with the formula instead.

I tried using this formula on my game and it works fine.

local percentage = count / #Assets
bar.Size = UDim2.fromScale(percentage, bar.Size.Y.Scale)

The only difference is you adding “OldXScale”, what is it set to?

I just found out what the problem was… FillBar variable was defined as both, the gray bar and the fill bar…

This stupid small problem lead to this huge mess I was dealing with for days.
Thanks for trying to figure out this problem with me :wink:

local Assets = game:GetDescendants()

for count, asset in pairs(Assets) do
	ContentProvider:PreloadAsync(
		{asset},
		function()
			GUI.Contents.Lower.AssetsLoaded.Text = "Assets loaded: "..count
			local Formula = UDim2.new(count / #Assets,0,FillBar.Size.Y.Scale,0)
			local BarTween = TweenService:Create(FillBar,TweenInfo.new(0.2, Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0,false,0),{Size = Formula})
			BarTween:Play()
		end
	)
end

UDim2.fromScale() is much easier and readable

1 Like

True, but sometimes it is useful to try similar functions in case the other isn’t working for some strange reason. Plus, I’ve never used UDim2.fromScale() before lol. :confounded:

PLUS, I don’t think you need to use OldScale. it will always update correctly. 499/1000 assets loaded and the X Scale would be 0.499 and 501/1000 assets loaded would make the X Scale 0.501. You don’t need to add OldScale.