In my game, I have a bunch of assets that I’m loading which consists of decals, sounds, and meshes. The problem is that all the failures are on the sounds and meshes. It doesn’t give a reason as to why either. The result just indicates failed. I have the assets grouped in tables of about 25 items each for performance reasons and so it can be skipped. I know the content URLs are good because I generated the list from a script that walks the game tree looking for specific classes that have IDs in them.
local player = playerService.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = nil
local loadBar = nil
local loadCounts = {
[Enum.AssetFetchStatus.Success.Name] = 0;
[Enum.AssetFetchStatus.None.Name] = 0;
[Enum.AssetFetchStatus.Failure.Name] = 0;
[Enum.AssetFetchStatus.Loading.Name] = 0;
[Enum.AssetFetchStatus.TimedOut.Name] = 0;
}
local assetTypes = {}
local assetLoadCount = 0
local skipEnableCount = 50
local loadingSkipped = false
local assetCount = 0
-- ******** Run
-- Normally, we put the run code at the bottom of
-- the file, but in this case, we need it here.
-- Set the new loading screen.
screenGui = replicatedFirst:WaitForChild("LoadingScreen"):Clone()
screenGui.Parent = playerGui
loadBar = screenGui.LoadBarFrame.Bar
-- Get the asset counts
for i = 1, #assetList, 1 do
assetCount += #assetList[i]
end
-- Normally, this would be in its own section, but since
-- we need the screenGui, it's placed here.
screenGui.Skip.TextButton.Activated:Connect(function()
loadingSkipped = true
end)
-- Remove the default loading screen.
replicatedFirst:RemoveDefaultLoadingScreen()
-- Preload Async Callback Function
local function preloadCallback(assetId, loadStatus)
--print("Asset Load:", assetId, loadStatus)
loadCounts[loadStatus.Name] += 1
assetLoadCount += 1
loadBar.Size = UDim2.new((assetLoadCount) / assetCount, 0, 0, 25)
-- For Debugging
if loadStatus ~= Enum.AssetFetchStatus.Success then
local st, ed = string.find(assetId, "rbxassetid://", 1, true)
if st ~= nil then
local assetIdNumber = tonumber(string.sub(assetId, ed + 1))
local data = marketplaceService:GetProductInfo(assetIdNumber)
if assetTypes[data.AssetTypeId] == nil then
assetTypes[data.AssetTypeId] = 1
else
assetTypes[data.AssetTypeId] += 1
end
end
end
end
-- Load Assets
if assetCount > 0 then
-- Load Assets
for i = 1, #assetList, 1 do
if i > 1 and i % 11 == 0 then
print("Pausing.... ", i)
task.wait(60)
end
local asset = assetList[i]
contentProvider:PreloadAsync(asset, preloadCallback)
if assetLoadCount > skipEnableCount then
screenGui.Skip.Visible = true
end
if loadingSkipped == true then
break
end
end
-- Display Results
print(string.format("ContentProvider:PreloadAsync Results:\n"), loadCounts,
string.format("\tTotal: %d", assetCount))
print(assetTypes)
end
-- Wait for the game to finsh loading.
if not game:IsLoaded() then
game.Loaded:Wait()
end
screenGui:Destroy()
The above script fragment does not include the services or the asset list. The asset list follows this format:
local assetList = {
{
-- Group 1 of about 25 assets.
};
{
-- Group 2 of about 25 assets.
};
{
-- Group 3 of about 25 assets.
};
{
-- Group n of about 25 assets.
};
}
When I do the run, I’m getting this in the output:
ContentProvider:PreloadAsync Results:
▼ {
["Failure"] = 441,
["Loading"] = 0,
["None"] = 0,
["Success"] = 142,
["TimedOut"] = 0
} Total: 583
{
[3] = 281,
[4] = 149
}
The first table contains the statistics based on what the Enum.AssetFetchStatus was. The second table is what asset types failed to load where 3 is sound and 4 is mesh. However, the sound and meshes do load because they are present in game.
So what’s going on?