Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i use instances with PreloadAsync()???

Asked by 6 years ago

Hello i have a script that is suppsoed to preload pictures so that they don't appear blank in my player gui. The pictures appear on a ImageButton inside a gui. However it gives me this error when i use the script:

Error: Unable to cast to Array Script 'Players.bondhemlig.PlayerGui.PictureLoading', Line 17 - local LoadAssets Script 'Players.bondhemlig.PlayerGui.PictureLoading', Line 29

People have been telling me that i need to use instances but i don't get it at all. I have a folder in workspace with stringvalues that contain the image ID of the picture i wanna use. There is another script using these values. However only two of the ID's are working and i just get a blank picture. So please don't answer that i need to use instances but also how i would do that!

Local Script:

repeat
local PlrGui=script.Parent
local PictureGui=PlrGui.VoteScreen.Back

wait(0.5)

print("DO")

local ContentProvider = game:GetService("ContentProvider")

local Pics={}

local function LoadAssets(AssetList)
    wait()
    for _, AssetId in ipairs(AssetList) do
        print(AssetId)
        ContentProvider:PreloadAsync(PictureGui.RandomMap)--instance?
        ContentProvider:PreloadAsync(PictureGui.RandomMap2)--instance?
    end
end


for i,v in pairs(game.Workspace.Values.MPics:GetChildren())do
    if v:IsA("StringValue")then
        table.insert(Pics,v.Value)
    end
end

LoadAssets(Pics)
until ContentProvider.RequestQueueSize <= 0
script:Remove()

Help would be really appreciated!

0
bump bondhemlig 20 — 6y

1 answer

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
6 years ago

PreloadAsync takes an array of instances. "Unable to cast to Array" is a good clue it tried to use your input as an array but failed.

0
ok bondhemlig 20 — 6y
0
ok boomer AbusedCocopuff4 105 — 4y
Ad

Answer this question