PreloadAsync() doesnt work?

If the person has a bad wi-fi they see this,


after few seconds the images appear.

but how do i make it so images get PRELOADED?
heres my preload script.

-- // Variables

local ContentProvider = game:GetService("ContentProvider")

local DayID = "rbxassetid://10489671462"
local DuskID = "rbxassetid://10489671574"
local NightID = "rbxassetid://10489671353"

local Day = script.Parent.Day.ImageButton
Day.Image = DayID
local Dusk = script.Parent.Dusk.ImageButton
Dusk.Image = DuskID
local Night = script.Parent.Night.ImageButton
Night.Image = NightID

local assets = { Day, Dusk, Night }

ContentProvider:PreloadAsync(assets)

print("Assets loaded.")

script location:
image

2 Likes

I might be wrong however, I think you need to use a LocalScript to preload the content (correct me if I’m wrong) and the way I would go about it is just like this:

-- services
local contentProvider = game:GetService("ContentProvider")

-- variables
local assets = {
	"rbsassetid://0",
	"rbsassetid://1",
	"rbsassetid://2",
}

-- functions
contentProvider:PreloadAsync(assets)

That way nothing yields in between the PreloadAsync function

is there something wrong with my code? it just doesnt seem to work

-- // Variables

local ContentProvider = game:GetService("ContentProvider")

local assets = {
	"rbsassetid://10489671462",
	"rbsassetid://10489671574",
	"rbsassetid://10489671353",
}

local DayID = assets[1]
local DuskID = assets[2]
local NightID = assets[3]

local Day = script.Parent.Day.ImageButton
Day.Image = DayID
local Dusk = script.Parent.Dusk.ImageButton
Dusk.Image = DuskID
local Night = script.Parent.Night.ImageButton
Night.Image = NightID

ContentProvider:PreloadAsync(assets)

print("Assets loaded.")
1 Like

Try this?:

-- // Variables

local ContentProvider = game:GetService("ContentProvider")

local assets = {
	"rbsassetid://10489671462",
	"rbsassetid://10489671574",
	"rbsassetid://10489671353",
}

ContentProvider:PreloadAsync(assets)

print("Assets loaded.")

local DayID = assets[1]
local DuskID = assets[2]
local NightID = assets[3]

local Day = script.Parent.Day.ImageButton
Day.Image = DayID
local Dusk = script.Parent.Dusk.ImageButton
Dusk.Image = DuskID
local Night = script.Parent.Night.ImageButton
Night.Image = NightID

And make sure this is a LocalScript and not a server script.

i accidently misspelt rbxassetid wrong. My GUIs are disabled first.
image
but when i click “singleplayer” they get enabled, could this be a problem?
image

When preloading a component it saves it in a cache, so when the component reappears somewhere it doesn’t need to download it, and it just grabs it from the cache. So the problem with having the gui disabled, shouldn’t be an issue. But the only issue on why PreloadAsync won’t work is either: not using a LocalScript to preload the components, or giving in the wrong component id’s. Recheck the id’s of the components you entered to make sure they’re the correct ones. You can do this by going to the image label(s), and looking at the Image property:

image

Then copy that property, and paste it into the assets table.

If after that it still doesn’t work, then I don’t really know why it wouldn’t work (possibly a roblox issue).

i checked absolutely everything, it is not working. Probably roblox issue.

3 Likes

Maybe its a script and not a local script?

How soon after loading the game do those GUIs appear? If they show up as soon as someone joins, the images still might not be loaded. Preloading doesn’t make them load faster than they otherwise would.

Oooo slendytubbies. But preload doesn’t work on UI. No matter what. The GUI has to be on screen for it to actually load.

1 Like

He’s preloading images, and that works whether you use them on UIs or not.

No game with a loading screen has loaded image guis in time. I’m pretty sure preloading doesn’t work on image guis.

You’re correct, but it does work on the images they use.

I don’t really know what you can do in this situation though. I think if you somehow make the GUI images be visible in the loading screen but the loading screen on top so it hides them then make them invisible again could make them load in time because they are loaded before the GUI actually appears.

1 Like

I believe PreloadAsync() Is working, or mostly in your code. From what I’ve gathered from the documentation page about PreloadAsync() is that it forces it into a queue ‘Request Queue’; normally assets are loaded and put into the queue when the client needs them, this is why they appear to load after the player has loaded in. With a basic, potentially incorrect, assumption PreloadAsync() only tells the client which assets to download first and not when they have finished downloading. I blieve if you pair this function with ContentProvide.RequestQueueSize it may lead to better results (Although suggested by Roblox that you shouldn’t base loading screens on this - RequestQueueSize*).

I’m not very keen on this subject myself, as I don’t personally use this service often. (Hope this helps)