You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
Im trying to make a loading screen, however the loading bar keeps getting stuck and never loads
-
What is the issue? Include screenshots / videos if possible!
robloxapp-20230608-1209203.wmv (364.8 KB)

The printing just stops printing
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried changing the positions of some of the code, but it never did anything.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local ContentProvider = game:GetService("ContentProvider")
local Players = game:GetService("Players")
local Percent = script.Parent:WaitForChild("LoadText")
local toLoad = game:GetDescendants()
local total = #toLoad
local MenuLoadSound = workspace.Sounds.Menu.Menu
local tween = game:GetService("TweenService")
local time = 1 --this will tell you how much it would take for the tween to finish
local tweeninfo = tween:Create(script.Parent, TweenInfo.new(time), {Transparency = 1})
game:GetService("ReplicatedFirst"):RemoveDefaultLoadingScreen()
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
MenuLoadSound:Play()
for i, v in ipairs(toLoad) do
print("loading")
Percent.Text = math.floor(i / total * 100) .. "%"
print(i, "/", total, "=", i/total)
ContentProvider:PreloadAsync({v})
end
print("Done loading!")
tweeninfo:Play()
I believe you are using the wrong loop in this scenario. You should be using the for i = loop instead.
Here is your updated code:
local ContentProvider = game:GetService("ContentProvider")
local Players = game:GetService("Players")
local Percent = script.Parent:WaitForChild("LoadText")
local toLoad = game:GetDescendants()
--local total = #toLoad
local MenuLoadSound = workspace.Sounds.Menu.Menu
local tween = game:GetService("TweenService")
local tweenTime = 1 --this will tell you how much it would take for the tween to finish
local tweeninfo = tween:Create(script.Parent, TweenInfo.new(tweenTime), {Transparency = 1})
game:GetService("ReplicatedFirst"):RemoveDefaultLoadingScreen()
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
MenuLoadSound:Play()
for i = 1, #toLoad do
print("loading")
Percent.Text = math.floor(i / #toLoad * 100) .. "%"
print(i, "/", #toLoad, "=", i/#toLoad)
local items = toLoad[i]
ContentProvider:PreloadAsync({items})
end
print("Done loading!")
tweeninfo:Play()
It just gives me an error that says, “Unable to cast Array to Content”
Could you please state which line you are receiving this error from?
ContentProvider:PreloadAsync({toLoad}) is where the error is coming from
I have identified the issue, and have updated the code above. It should work fine now
I mean, it works now. But it still randomly gets stuck at a certain percentage.
I believe the reason for your issue could be because you have a variable set for the number of instances in the game, and many instances likely still haven’t loaded in the game at the time this script runs.
I have updated the code again in my post above.
If that still doesn’t fix the issue, could you please show the print statement in the output?
You could try HoToRoblox’s YT vid on loading screens. Works really well: