Tutorial - How to preload image labels/image buttons

Using ContentProvider to preload image labels or preload image ids doesnt work. Thats why i came up with this solution.

The solution is that you create a new ScreenGui and in there you create ImageLabels with your desired ids.
(LocalScript in ReplicatedFirst)

local loaderGui = Instance.new("ScreenGui")

local ids = {"rbxassetid://70560882025207", "rbxassetid://81680325506946"}
for _, id in ids do
	local label = Instance.new("ImageLabel")
	label.Image = id
	label.Parent = loaderGui
end

loaderGui.Parent = player.PlayerGui

Alternatively you can do this:

local function hasProperty(object, propertyName)
	local success, _ = pcall(function() 
		object[propertyName] = object[propertyName]
	end)
	return success
end

local loaderGui = Instance.new("ScreenGui")

for _, v in desiredScreenGui:GetDescendants() do
	if not hasProperty(v, "Visible") then continue end
	
	local a = v:Clone()
	a.Visible = true
	a.Parent = loaderGui
end

loaderGui.Parent = player.PlayerGui

We obviously dont want the player to see this so we put up a fake loading screen with its DisplayOrder property set to a high number so it renders above the image label gui.

And thats it! All of your images should now be loaded.

9 Likes