I’m trying to force a PreloadAsync to only pass when it’s successfull,
- They’re all failing,
and - the Pcall isn’t working and is allowing the script to continue on.
local Player = game:GetService("Players").LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ContentProvider = game:GetService("ContentProvider")
local Assets = require(ReplicatedStorage:WaitForChild("Assets", 60))
local LoadingGui = Player.PlayerGui:WaitForChild("LoadingGui", 60)
local LoadingBar = LoadingGui.Background.Loading.Main.Bar
local AssetCountLabel = LoadingGui.Background.Loading.AssetCount
local TotalAssetsLoaded = 0
AssetCountLabel.Text = "Loaded Assets: " .. TotalAssetsLoaded .. "/" .. #Assets.Ids
for _, Asset in ipairs(Assets.Ids) do
local Success
while not Success do
Success = pcall(function()
ContentProvider:PreloadAsync({Asset})
end)
wait()
end
if Success then
TotalAssetsLoaded = TotalAssetsLoaded + 1
LoadingBar.Size = UDim2.fromScale(TotalAssetsLoaded/#Assets.Ids)
AssetCountLabel.Text = "Loaded Assets: " .. TotalAssetsLoaded .. "/" .. #Assets.Ids
end
end