Hello,
I am trying to do a loading bar for my new game. It preloads assets to make sure there are not any assets left unloaded.
So, I try to make the loading bar going “up” instead of going “down”. The way I am doing it right now is dividing the assets left with all the assets that needs to be loaded, but this makes the loading bar go down.
Here’s a gif to show you: https://gyazo.com/5907e369c1319e4ab90d59fefbf88b5f
This is the code im using right now:
-- Constants
local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local localPlayer = Players.LocalPlayer
local UI = script.Loading
-- Variables
local MIN_TIME = 5
local count = 0
-- Logic
local new = UI:Clone()
new.Parent = localPlayer:WaitForChild("PlayerGui", 3)
ReplicatedFirst:RemoveDefaultLoadingScreen()
local startTick = tick()
local WorkspaceAssets = workspace:GetDescendants()
local PlayerGuiAssets = localPlayer.PlayerGui:GetDescendants()
for Id,Asset in pairs(WorkspaceAssets) do
local AssetsLeft = #WorkspaceAssets - Id + 1
if AssetsLeft == 1 then
new.Container.AssetsProgress.Text = "Loading... (1 Asset Left)"
else
new.Container.AssetsProgress.Text = "Loading... ("..AssetsLeft.." Assets Left"
end
new.Container.Loading.Bar:TweenSize(UDim2.new(AssetsLeft / #WorkspaceAssets, 0, 1, 0))
game:GetService("ContentProvider"):PreloadAsync({Asset})
print(AssetsLeft)
wait(1)
end
for Id,Asset in pairs(PlayerGuiAssets) do
local AssetsLeft = #PlayerGuiAssets - Id + 1
if AssetsLeft == 1 then
new.Container.AssetsProgress.Text = "Loading... (1 Asset Left)"
else
new.Container.AssetsProgress.Text = "Loading... ("..AssetsLeft.." Assets Left"
end
new.Container.Loading.Bar:TweenSize(UDim2.new(AssetsLeft / #PlayerGuiAssets, 0, 1, 0))
game:GetService("ContentProvider"):PreloadAsync({Asset})
print(AssetsLeft)
wait(1)
end
print("Done")
This is the structure of the loading screen: Screenshot by Lightshot
I tried looking at the developer forum, but it just shows how to do it if you already know how many assets you loaded.
Thanks in advance.
Edit: I solved it myself.