I have this loading script. However, it’s very inconsistent. Randomly, it’ll show 1.4k or 2.4k assets which I know very well that’s not true.
local ts = game:GetService("TweenService")
local info = TweenInfo.new(.3, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut)
local ContentProvider = game:GetService("ContentProvider")
local UI = script:WaitForChild("LoadingGui"):Clone()
repeat task.wait() until game:IsLoaded()
local assets = game:GetDescendants()
local MaxAssets = #assets
local plr = game.Players.LocalPlayer
local plrGui = plr:WaitForChild("PlayerGui")
local tween = ts:Create(UI.MainFrame, info, {BackgroundTransparency = 1})
UI.Parent = plrGui
for i, AssetToLoad in assets do
ContentProvider:PreloadAsync({AssetToLoad})
UI:WaitForChild("MainFrame"):WaitForChild("Counter").Text = i.."/"..MaxAssets
end
tween:Play()
tween.Completed:Connect(function()
UI:Destroy()
end)
For cleaner code, I would reccomend just creating a temporary object, preloading it, then deleting it.
local Animations = {
14892039610;
11766457253;
11766177400;
11760464346;
}
--//Creation and Loading
for i,v in ipairs(Animations) do
local NewAnim = Instance.new("Animation")
NewAnim.Parent = script
NewAnim.AnimationId = "rbxassetid://"..v
table.insert(P_Anims,NewAnim)
end
Content:PreloadAsync(P_Anims)
--//Cleanup
for i,v in ipairs(Animations) do
v:Destroy()
end
table.clear(Animations)