ImageLabel keeps flickering after updating image id

Hi! I am doing a video by image frame by frame method, but after I updated the image id then the screen starts flickering. Is there any solution to this? Or do I need to preload the images?

I am currently using this method:
https://devforum.roblox.com/t/how-to-make-gifs-and-videos-on-roblox-full-tutorial/1667260

Here is my code:

local localplayer = game:GetService("Players").LocalPlayer
local rs = game:GetService("ReplicatedStorage")
local contentprovider = game:GetService("ContentProvider")

local camerashake = require(game.ReplicatedStorage.CameraShaker)
local Video = localplayer.PlayerGui:WaitForChild("Video")

local HollowPurpleIDTable = { -- 63 image frames goes here
	[1] = "rbxassetid://blabla",
}

game.ReplicatedStorage.RE.ClientFX.OnClientEvent:Connect(function(type, theone)
	local currentFrame = 0
	
	if type == "HollowPurpleVideo" then
		Video.Enabled = true
		Video.ImageHere.ImageTransparency = 0
		
		repeat task.wait(0.05) 
			currentFrame += 1
			local imageId = HollowPurpleIDTable[currentFrame]
			Video.ImageHere.Image = imageId
			print(currentFrame)
		until currentFrame >= 63
		
		game:GetService("TweenService"):Create(Video.ImageHere, TweenInfo.new(1.5), {ImageTransparency = 1}):Play()
		
		print('ended')
end

you should preload the images. the reason it ‘flickers’ because the image needs to load in order to display in ImageLabel

How do I preload it? I tried ContentProvider:PreloadAsync but it’s still flickering.

What is your PreloadAsync code?

local preloadIDTable = {} -- asset ids here

local instanceTable = {}

for _, id in ipairs(preloadIDTable) do
	local instance = Instance.new("ImageLabel")
	instance.Image = "rbxassetid://"..id
	table.insert(instanceTable, instance)     
end

contentprovider:PreloadAsync(instanceTable)

I copied this from a post, I forgot which one though. And also editted this thing a bit.

Can you try this and see what it prints?

local preloadIDTable = {}

local instanceTable = {}

for _, id in ipairs(preloadIDTable) do
    local instance = Instance.new("ImageLabel")
    instance.Image = "rbxassetid://"..id
    table.insert(instanceTable, instance)
end

local contentprovider = game:GetService("ContentProvider")
local success = contentprovider:PreloadAsync(instanceTable)

if success then
    print("They're all loaded")
else
    warn("Image preload failed.")
end

It says “Image preload failed.”

Update the last bit to this:

local contentprovider = game:GetService("ContentProvider")
local success, errorMsg = contentprovider:PreloadAsync(instanceTable)

if success then
    print("They're all loaded")
else
    warn("Image preload failed.",errorMsg)
end

What does it print?

“Image preload failed. nil”

How do I fix this?

I assume you added your roblox ids to the table right?

Yes, I am.

There, the table I am using.

local preloadIDTable = {15155878931,15155878775,15155878627,15155878476,15155878186,15155877918,15155877678,15155877510,15155880841,15155880635,
	15155880502,15155880374,15155880168,15155880025,15155879813,15155879610,15155879477,15155879346,15155879164,15155882850,
	15155882651,15155882341,15155882156,15155881878,15155881576,15155881401,15155881172,15155880983,15155883237,15155883016,
	15155885884,15155885644,15155885384,15155885133,15155884953,15155884781,15155884483,15155884200,15155884038,15155883887,
	15155883603,15155888031,15155887806,15155887609,15155887413,15155887245,15155887106,15155886885,15155886691,15155886524,
	15155886083,15155890200,15155889946,15155889781,15155889593,15155889425,15155889205,15155889028,15155888868,15155888570,15155888327,15155890385,15155978828
}

Could you try just this code and see if they even load at all?

for i,v in pairs(preloadIDTable) do
	local succ, errFail = pcall(function()
		game:GetService("ContentProvider"):PreloadAsync({asset})
	end)
	if succ then
		print("finished loading "..v..".")
	else
		warn("ID"..v.." could not load due to "..errFail)
	end
end
print("done")

Every assets can’t be loaded with the same error.

“ID… could not load due to Unable to cast double to Content”

I am starting to get it now.
Does it need to be string?

I’m not sure, but you could try that.

EDIT:
Or maybe add rbxasset in front of it.

for _, assetID in ipairs(preloadIDTable) do
    local assetString = "rbxassetid://" .. tostring(assetID)
    local success, errorMsg = pcall(function()
        game:GetService("ContentProvider"):PreloadAsync({assetString})
    end)
    
    if success then
        print("Finished loading " .. assetID .. ".")
    else
        warn("ID " .. assetID .. " could not load due to " .. errorMsg)
    end
end

print("Done")

Every assets are printed as finished loading, however it’s still flickering.

Did you try my edit code? With the rbxasset in front?

Yep, I tried. But it’s still flickering.

Maybe add a wait?
Like 10 seconds or 15 seconds after the done is printed, then use them ingame

Still not working, I wonder why.

Here’s the video of it.
https://streamable.com/6za7r2

Thats very weird, i don’t really have an idea anymore. Sorry :+1: