How i can use ContentProvider to do a loading gui thing, also how would i’ll convert them to a number, so i can do a bar, Is this the best form to do a loading gui too?, or there is others
I’m no scripter but I followed a YouTube tutorial and it showed me exactly how to make a loading GUI pretty easily. Most YouTube tutorials are helpful so you should be able to pick whichever you want and change it as you please.
There’s many different Loading GUI forms. Not sure which one is the absolute best though.
One way you can do this is to load in every asset one by one using ContentProvider:PreloadAsync
, then update the ratio between the loaded assets and the total assets:
local assets = your.assets.Here -- must be an array
local total = #assets
for completed, asset in ipairs(assets) do
ContentProvider:LoadAsync({asset})
local ratio = completed/total
print(ratio*100, "% loaded")
yourLoadingBar.Size = UDim2.new(ratio, 0, 1, 0) -- assuming you are using a horizontal bar with scale
-- simply adjust this to the loading screen design you want
end
If you want something more precise (ie; considering everything that is being loaded in via PreloadAsync
), you can try using RequestQueueSize
instead, but be wary as this value increases and decreases arbitrarily based on what you pass onto the method, meaning you will have to handle adjustments on your own.
local BarProgress = 0
while wait() do
BarProgress = BarProgress + 0.5
script.Parent.Size = UDim2.new(BarProgress/100, 0, 0.1, 0)
script.Parent.Parent.LoadingText.Text = ("Loading... "..math.floor(BarProgress*2).."%")
if BarProgress == 50 then
game.Workspace.Ding:Play()
wait(1)
while wait() do
script.Parent.BackgroundTransparency = script.Parent.BackgroundTransparency + 0.08
script.Parent.Parent.BarBackground.BackgroundTransparency = script.Parent.Parent.BarBackground.BackgroundTransparency + 0.08
script.Parent.Parent.LoadingText.TextTransparency = script.Parent.Parent.LoadingText.TextTransparency + 0.08
script.Parent.Parent.BackgroundTransparency = script.Parent.Parent.BackgroundTransparency + 0.072
if script.Parent.BackgroundTransparency >= 1 then
script.Parent.Parent.Parent:Destroy()
break
end
end
end
end
Here is the loading script, but one thing, if you want a ding sound or someother sound after it completes loading then, you can just edit at the place of “Ding” in this code game.Workspace.Ding:Play()
script:WaitForChild("Loading"):Clone().Parent = game.StarterGui
script:Destroy()
And here is the Loading bar script.