Preloading images and keeping them loaded!

Preloading images and keeping them loaded!

Are you tired of your game not having assets loaded when entering a new scene? Is PreloadAsync not keeping the textures loaded? I found myself in this situation so I’m making this tutorial to help others.

Step One

Make a list of all the Asset IDs you want to load. This will be used to create the ImageLabels that forceload the assets.

local assets = {
	"rbxassetid://1",
	"rbxassetid://2",
	"rbxassetid://3",
	"rbxassetid://4",
	"rbxassetid://5",
	"rbxassetid://6",
	"rbxassetid://7",
	"rbxassetid://8",
	"rbxassetid://9"
}

Step Two

Create a ScreenGui in the local player’s PlayerGui that does not reset on spawn. You should also set IgnoreGuiInset to true

local preloadFrame = Instance.new("ScreenGui")
preloadFrame.ResetOnSpawn = false
preloadFrame.IgnoreGuiInset = true
preloadFrame.Parent = game.Players.LocalPlayer.PlayerGui

Step Three

Make a function that goes through a list and creates a 1x1 image label that has 100% background transparency and 90% image transparency based on Asset IDs in the table. This is our main function, it is what forces the images to load and stay loaded.

local function makePreloadFrame(list)
    for i,v in pairs(list) do
        local new = Instance.new("ImageLabel")
        new.Image = image
        new.Position = UDim2.fromOffset(i,0)
        new.Size = UDim2.fromOffset(1,1)
        new.BackgroundTransparency = 1
        new.ImageTransparency = 0.9
        new.Parent = preloadFrame
    end
end

Step 4

Run makePreloadFrame() on the asset table

makePreloadFrame(assets)

Step 5

Call ContentProvider:PreloadAsync() on the image labels we creates

game:GetService("ContentProvider"):PreloadAsync(preloadFrame:GetChildren())

Since the images are technically visible they are never unloaded but they are basically invisible. Note that doing this can significantly increase your memory usage depending on the amount of images you have.

7 Likes