I have 149 image labels that are used to create an animated intro. However, there are times where frames are being skipped, I believe due to these images not actually being loaded. However, I preload all the images first before doing the animation, and there are some times where image does not load at all
-- Preload Everything
for i = 1, #PreloadAssets do
ContentProvider:PreloadAsync(PreloadAssets[i])
UpdateLoadingValue(i / #PreloadAssets)
print(i / #PreloadAssets)
end
print("Intro assets have loaded successfully")
-- Initializing all frames for the animation sequence
local AnimationBufferIndices = 30 -- How many frames are onscreen at once to guarantee visibility
local IntroAnimationImages = table.create(#Ids, nil)
for i, imageId in ipairs(Ids) do
local Img = LoadingUI.Animation.ImageTemplate:Clone()
if i <= 50 then
Img.Parent = LoadingUI.Animation
else
Img.Parent = nil
end
Img.Position = UDim2.fromScale(1.5, 0.5)
Img.Image = imageId
Img.Visible = true
-- Storage
IntroAnimationImages[i] = Img
end
-- this is the loop that does the animation
for i, image in ipairs(IntroAnimationImages) do
image.Position = UDim2.fromScale(0.5, 0.5)
-- Hide Last Frame
if PrevImage then
PrevImage.Position = UDim2.fromScale(1.5, 0.5)
PrevImage:Destroy()
end
print(i, image)
PrevImage = image
task.wait(AnimationSpeed)
end
If any assets failed to load, PreloadAssets should announce this in the Output. If you got no output, then there’s a chance you weren’t preloading anything.
While we can’t see your PreloadAssets table, this could have something to do with it.
If your PreloadAssets table consists only of ID numbers, it’s not preloading anything. For example:
This is just a guess based on the behavior of ContentProvider:PreloadAsync more than the code you’ve provided here.
The number of assets you attempt to preload at once shouldn’t be a problem, because it yields until it’s finished.
You can time your preloading efforts like this:
local startTime = os.clock()
ContentProvider:PreloadAsync(assets)
local deltaTime = os.clock()
print(("Preloading complete, took %.2f seconds"):format(deltaTime))
If it happens instantly, then you know for certain that your code didn’t actually attempt to preload your assets.
This is what’s being preloaded. I assume PreloadAsync preloads image ids??
I also segment them into seperate chunks, so preloading 140+ images a single table takes a considerably longer time than a table of 20. Once the images have been preloaded, I create all the imagelabels, store them, then after loop through them to create a slideshow affect. Unsure if this is the best approach, if I should be just creating 1 imagelabel and changing it’s id rapidly. I feel that would be worse tho, as Imagelabels take a split second to load their images it seems, but idk
The images are 100% being added to the preload table, and are 100% being preloaded, as I’ve added prints to confirm this + it yields. It does 8 tables (7 with 20, last one with 9, so total of 149 image ids) and as mentioned earlier, breaking them up into smaller tables made preloading them a lot faster over just preloading the entire 149 image id table (that took up to 50-60 seconds to preload them all, can’t have that) while the shortened table takes about 5-6 seconds, depending on connection.
local PRELOAD_ASSET_BUFFER_SIZE = 20
local PreloadAssets = {[1] = {}}
local PreloadAssetIndex = 1
local function AddAsset(assetId)
-- Add
table.insert(PreloadAssets[PreloadAssetIndex], assetId)
-- Max Size, increment counter
if #PreloadAssets[PreloadAssetIndex] == PRELOAD_ASSET_BUFFER_SIZE then
PreloadAssetIndex += 1
PreloadAssets[PreloadAssetIndex] = {}
end
end
for _, assetId in ipairs(Ids) do
AddAsset(assetId)
end
-- Preload Everything
for i = 1, #PreloadAssets do
ContentProvider:PreloadAsync(PreloadAssets[i])
end
-- Create the image labels
for i, imageId in ipairs(Ids) do
local Img = LoadingUI.Animation.ImageTemplate:Clone()
Img.Parent = LoadingUI.Animation
Img.Position = UDim2.fromScale(1.5, 0.5)
Img.Image = imageId
Img.Visible = true
-- Storage
IntroAnimationImages[i] = Img
end
-- Do the animation
local AnimationSpeed = 1 / 42
local PrevImage = nil
local BufferRefilCheck = 10
local BufferRefilIndex = AnimationBufferIndices + 1
for i, image in ipairs(IntroAnimationImages) do
image.Position = UDim2.fromScale(0.5, 0.5)
-- Hide Last Frame
if PrevImage then
--PrevImage.Position = UDim2.fromScale(1.5, 0.5)
PrevImage:Destroy()
end
PrevImage = image
-- Check if approaching buffer limit
if i + BufferRefilCheck == BufferRefilIndex then
-- Start reparenting more frames
local NewMax = math.min(BufferRefilIndex + AnimationBufferIndices, #IntroAnimationImages)
for i = BufferRefilIndex, NewMax do
IntroAnimationImages[i].Parent = LoadingUI.Animation
end
BufferRefilIndex = NewMax + 1
end
task.wait(AnimationSpeed)
end
You are still understanding what my problem is. I know PreloadAsync yields, I clearly say it right here
How would ReplicatedFirst fix any of this!? The script is in ReplicatedFirst, I have 149 ids that need to laod. I’m not gonna manually make all them into imagelabels and do that. As I have said numerous times, ALL 149 images are LOADING! So Preload is ‘working’. When I apply their ids to an ImageLabel however, they do not work and load instantly