Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Preloading images does nothing? [SOLVED]

I have some code which loads images since I'm basically planning to play a video in a GUI. But no matter how I use the PreloadAsync function the images still are invisible for like a quarter of a second after being set as the image property so the video is basically just completely invisible. Anyone know how to properly use PreloadAsync for this idea?

TL;DR How do you properly use PreloadAsync so the images I set in a GUI don't take a while to load when applied so an image animation can be played?

You've asked for the code, here you go

local frames = 302

print("Loading...")

local hahaha = {

}

for i = 1, frames do
	table.insert(hahaha, "rbxgameasset://Images/frame" .. i)
end

game:GetService("ContentProvider"):PreloadAsync(hahaha)

print("Starting in 1 second!")

wait(1)

print("Started!")

for i = 1, frames do
	wait()
	script.Parent.Image = "rbxgameasset://Images/frame" .. i
end

2 comments

0

In the for loop you forgot the increment?

0

Which loop?

1 answer

Problem solved, I made the PreloadAsync code create a bunch of frames and handle them in a specific way so they don't unload.

local frames = 302

local images = {

}

local lastitem = nil

local function test(contentId)
	if lastitem ~= nil then script.Parent.Frames[lastitem].ImageTransparency = 0.999 end
	local item = script.Parent.Frame:Clone()
	item.Parent = script.Parent.Frames
	item.Name = "frame" .. string.sub(contentId, 28, #contentId)
	item.Visible = true
	item.Image = contentId
	lastitem = item.Name
	print("Created " .. lastitem)
end

for i = 1, frames do
	table.insert(images, "rbxgameasset://Images/frame" .. i)
end

print("Waiting 3 seconds then starting.")

wait(3)

script.Parent.Frame.Visible = false

game:GetService("ContentProvider"):PreloadAsync(images, test)

print("Starting in 2 seconds!")

wait(2)

script.Parent.Frames[lastitem].ImageTransparency = 0.999

for i = 1, frames do
	wait()
	print("Hid " .. lastitem .. " and showed  " .. "frame" .. i)
	if script.Parent.Frames:FindFirstChild("frame" .. i) then
	script.Parent.Frames[lastitem]:Destroy()
	script.Parent.Frames["frame" .. i].ImageTransparency = 0
	script.Parent.Frames["frame" .. i].ZIndex = i
	lastitem = "frame" .. i
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.