I have a problem that I can’t seem to fix right now. And yes, I’ve been to about 5 different DevForum discussions about it. I have a script that checks certain assets and waits for them to be loaded, but it doesn’t seem to be working. I’m putting the script and a link that I found below:
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local ContentProvider = game:GetService("ContentProvider")
ReplicatedFirst:RemoveDefaultLoadingScreen()
local assetsLoaded = 0
local assetsToLoad = {
game.Workspace:GetDescendants(),
player:WaitForChild("PlayerGui"):WaitForChild("MainGui"):GetDescendants(),
game.ReplicatedFirst:GetDescendants(),
game.ReplicatedStorage:GetDescendants()
}
print(assetsToLoad)
for _, asset in pairs (assetsToLoad:GetChildren()) do
ContentProvider:PreloadAsync({asset})
assetsLoaded+=1
script.Parent.LoadingFrame.Background.Progress.Size= UDim2.new(#assetsToLoad/assetsLoaded,0,0,0)
end
Oh I didn’t even put the error. The error was “Unable to cast Array to Content” @myaltaccountsthis is that going to be a problem with the performance, or is it just saying I’m using the wrong word?
It’s not necessary to call :GetChildren() on assetsToLoad as it is already a table which you can loop through using pairs(). You do not need to pass in {asset} inside the ContentProvider:PreloadAsync() function, instead just pass the asset variable without the {} around it.
How do people normally show loading, like, a good example, Infinite Autocorrect, where it shows every “asset”? Is that not every part in the game then?