I’m quite confused on how to use PreloadAsync. The documentation says to pass in an array of Instances, but then the code sample below uses roblox content links:
local ContentProvider = game:GetService("ContentProvider")
local waitingImage = "rbxassetid://1234561"
local thumbLeft = "rbxthumb://type=Avatar&id=1234&w=100&h=100"
local thumbRight = "rbxthumb://type=Avatar&id=1235&w=100&h=100"
local failedImageLeft = "rbxassetid://1234562"
local failedImageRight = "rbxassetid://1234563"
local labelLeft = script.Parent.LabelLeft
labelLeft.Image = waitingImage
local labelRight = script.Parent.LabelRight
labelRight.Image = waitingImage
local assets = { thumbLeft, thumbRight }
local function setThumb(contentId, status)
if thumbLeft == contentId then
labelLeft.Image = Enum.AssetFetchStatus.Success == status and thumbLeft or failedImageLeft
elseif thumbRight == contentId then
labelRight.Image = Enum.AssetFetchStatus.Success == status and thumbRight or failedImageRight
end
end
spawn(function()
ContentProvider:PreloadAsync(assets, setThumb)
end)
So, the documentation never mentions that you can pass in strings - is the code sample outdated or the documentation?
I believe the documentation just updated recently
From what I understand on searching the DevForum, attempting to load in strings
as values would make PreloadAsync
assume it as some sort of ImageLabel
ID & if it’s not valid then it’d result as an error
To be safe, just only insert Objects & Instances that you would want to Preload when calling that function
If the instances passed in were destroyed, are the images cached? Or would they have to be loaded in again later?
I believe if you were to destroy them, that’d just result as an error or warning since PreloadAsync
goes through the entire current array
If you’re wanting to load them again, every Instance would need to be valid & visible to the client side so that it’s able to load everything correctly
Hmm, I’m trying to figure out how to preload textures during a loading screen, without having the actual objects in game exist yet. I thought I could quickly create instances with the texture ids, preload them, destroy those instances, then leave the loading screen.
You could probably do something along the lines of this:
local ContentProvider = game:GetService("ContentProvider")
local StartTime = os.clock()
local Asset1 = Instance.new("Decal")
Asset1.Texture = "rbxassetid://Something" --Idk what Decal properties are
local Asset2 = Instance.new("Part")
Asset2.Name = "RandomPart"
local AssetsToLoad = {
Asset1,
Asset2,
}
ContentProvider:PreloadAsync(AssetsToLoad)
local DeltaTime = os.clock() - StartTime
print(("Preloading complete, took %.2f seconds"):format(DeltaTime))
Found it