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

PreloadAsync is not working, am I using it properly?

Asked by
SCP774 191
6 years ago

Well, I've created an inventory GUI, everything is done but when I test it, the decals failed to preload. Anyone got any idea on what happened?

Here's the script itself:

wait(1)
local rep = game:GetService("ReplicatedStorage")
local remote = rep.Remotes:WaitForChild("GetPlayerItemInfoCTC")
local remote2 = rep.Remotes:WaitForChild("SendPlayerItemInfoEvent")
local remote3 = rep.Remotes:WaitForChild("InventoryControlEvent")
local remote4 = rep.Remotes:WaitForChild("CloseAllGuisCTC")
local frame = script.Parent
local gui = frame.Parent
local panelHolder = frame:FindFirstChild("BlankHolder")
local plr = game.Players.LocalPlayer
local itemModule = require(rep.Modules.ItemLibrary)
local contentProvider = game:GetService("ContentProvider")

local quanityList = {}

local itemInfo = {}

local function checkHorizontalNumber(id, line)
    if line == 1 then
        return id
    else
        local preOperator = line - 1
        local operator = 4 * preOperator
        local formula = id - operator
        return formula
    end
end

local itemInfo = remote:InvokeServer()

wait(1)
for i, v in pairs(itemInfo) do
    print(i,v)
    local lineNumber = math.ceil(i / 4)
    local HorizontalId = checkHorizontalNumber(i, 1)
    local additional = HorizontalId - 1
    local additional2 = lineNumber - 1
    local Coordinate = UDim2.new(0, 135 * additional, 0, 135 * additional2)
    local obtainedItemName, obtainedItemInfo = itemModule.GetItem(v)
    wait(0.25)
    if obtainedItemInfo then
        local itemTier = itemModule.TierValue(v)
        local targetPanel = panelHolder:FindFirstChild("Panel"..i)
        if targetPanel then
            targetPanel.ToolName.Text = obtainedItemName
            targetPanel.ItemImage.Image = "rbxassetid://"..obtainedItemInfo.image
            wait()
            contentProvider:PreloadAsync({targetPanel.ItemImage})
        else
            local newPanel = panelHolder.Panel1:Clone()
            newPanel.Name = "Panel"..i
            newPanel.Parent = panelHolder
            newPanel.ToolName.Text = obtainedItemName
            newPanel.Position = Coordinate
            newPanel.ItemImage.Image = "rbxassetid://"..obtainedItemInfo.image
            wait()
            contentProvider:PreloadAsync({newPanel.ItemImage})
        end
    end
end

The item library is just a module script that stores all information for all gears.

Here's the output: 1 Wood Club Starting Module 20:50:36.140 - ContentProvider:PreloadAsync() failed for rbxassetid://2331348483 2 Alpha Sword Starting Module 20:50:36.487 - ContentProvider:PreloadAsync() failed for rbxassetid://2331348483

The game is a group game, and the decal's owner is the group. This should've worked properly but it didn't, if you can find any problem please tell me, all help appreciated.

Answer this question