My image preloader doesn't work?

Any ideas why this doesn’t work?

local ContentProvider = game:GetService("ContentProvider")
local RunService = game:GetService("RunService")

local rawIds = {
	"rbxassetid://109855713834762",
	"rbxassetid://98357168380552",
	"rbxassetid://92573911917908",
	"rbxassetid://89442524877608",
	"rbxassetid://105669259984506",
	"rbxassetid://115411795601393",
	"rbxassetid://116825119604738",
	"rbxassetid://107560542876600",
	"rbxassetid://123306046844820",
	"rbxassetid://133800578448288",
	"rbxassetid://120054839750576",
	-- kill streaks
	"rbxassetid://90000502672534",
	"rbxassetid://80007191195622",
	"rbxassetid://131154973078209",
	"rbxassetid://106652328809162",
	"rbxassetid://104927421424159",
	"rbxassetid://77969614336539",
}

local seen = {}
local assets = {}

for _, id in ipairs(rawIds) do
	if not seen[id] then
		seen[id] = true
		table.insert(assets, id)
	end
end

RunService.RenderStepped:Wait()

pcall(function()
	ContentProvider:PreloadAsync(assets)
end)

According to the documentation on ContentProvider:PreloadAsync(), it " Yields until all of the assets associated with the given Instances have loaded." This means that you would probably need to create a new decal to load the images.

https://create.roblox.com/docs/reference/engine/classes/ContentProvider#PreloadAsync

your for loop isn’t doing anything, it’s just copying the ids from one table into another. Also PreloadAsync is lowkey a scam for images, you have to display them and wait until the .IsLoaded property is true to actually preload.

code you can run in console to see the loading effect. Edits to make it work in your game are commented:

--put your images here, could also require a module
local imageIDs = {
	"rbxassetid://109855713834762",
	"rbxassetid://98357168380552",
	"rbxassetid://92573911917908",
	"rbxassetid://89442524877608",
	"rbxassetid://105669259984506",
	"rbxassetid://115411795601393",
	"rbxassetid://116825119604738",
	"rbxassetid://107560542876600",
	"rbxassetid://123306046844820",
	"rbxassetid://133800578448288",
	"rbxassetid://120054839750576",
	-- kill streaks
	"rbxassetid://90000502672534",
	"rbxassetid://80007191195622",
	"rbxassetid://131154973078209",
	"rbxassetid://106652328809162",
	"rbxassetid://104927421424159",
	"rbxassetid://77969614336539",
}

--THIS ONE IS JUST ONE SHOT LOADING
local function _createLoaderGui()
	local elapsedProgress = 0
	local loadingScreenGui = Instance.new("ScreenGui")
	local uIGridLayout = Instance.new("UIGridLayout")
	uIGridLayout.CellSize = UDim2.fromOffset(10, 10)
	uIGridLayout.CellPadding = UDim2.fromScale(0, 0)
	uIGridLayout.Parent = loadingScreenGui

	--If you want to test it in console, use the game.StarterGui as the parent
	--For your game, parent the loadingScreenGui to the PlayerGui
	loadingScreenGui.Parent = game.StarterGui
	-- loadingScreenGui.Parent = player:WaitForChild("PlayerGui")

    task.defer(function()
        for i = 1, #imageIDs do
            task.spawn(function()
                local imageLoaderHolder = Instance.new("ImageLabel")
                imageLoaderHolder.Image = imageIDs[i]
                imageLoaderHolder.Parent = loadingScreenGui

                repeat
                    task.wait()
                until imageLoaderHolder.IsLoaded
                elapsedProgress+=1
				print(string.format("%.2f", (elapsedProgress / #imageIDs) * 100) .. "%")
            end)
        end
    end)

    repeat
        task.wait()
    until elapsedProgress >= #imageIDs

	-- Destroy the loadingScreenGui here, I just tagged it out so you can see it in console when testing
	-- loadingScreenGui:Destroy()
	-- loadingScreenGui = nil
	print("all loaded")
    return
end

_createLoaderGui() --this yields

In the video, it shows what the preload looks like. It waits until all the images are visible

Let me know if you have any questions :slight_smile:

That’s what I’ve used! I hate how ContentProvider doesn’t actually load anything.

Also I’m pretty sure you can set the images smaller to 1x1 pixel and set the transparencies high to like 0.95+ (maybe 0.99 doesn’t work?)

Yeah probably can, I usually have a loading screen to cover the images being loaded to hide it from the player

Really odd, don’t understand why they would set it up that way. But alright thank you.
I could just create 1 decal and then assign each image in a loop very quickly? Would that work.