So I've made a massive inventory system that works similar to Murderer Mystery 2's one. It's data transfer and saving part is completed (And tested), but I'm having trouble with the panel generation.
It shows no error and I already debugged it nothing went wrong but a new panel didn't create.
Here's my script:
wait(2.5) 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 print("Invoking for info") local itemInfo = remote:InvokeServer() wait(2.5) print("Printing inventory info") for i, v in pairs(itemInfo) do print(i,v) print("Creating information for panel") local lineNumber = 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) print("Obtaining information for item") local obtainedItemName, obtainedItemInfo = itemModule.GetItem(v) wait(0.5) if obtainedItemInfo then print("Information obtained") local itemTier = itemModule.TierValue(v) local targetPanel = panelHolder:FindFirstChild("Panel"..i) if targetPanel then print("Panel already exists") targetPanel.ToolName.Text = obtainedItemName targetPanel.Image.Image = "rbxassetid://"..obtainedItemInfo.image local assetToPreload = {targetPanel.Image} contentProvider:PreloadAsync(assetToPreload) else print("Creating new panel") local newPanel = panelHolder.Panel1:Clone() newPanel.Name = "Panel"..i newPanel.ToolName.Text = obtainedItemName newPanel.Position = Coordinate newPanel.Image.Image = "rbxassetid://"..obtainedItemInfo.image local assetToPreload = {newPanel.Image} contentProvider:PreloadAsync(assetToPreload) end end print("Ending function") end
For the item library module:
local module = {} local tableOfTier = { ["Starter"] = 1; -- Receive when first joined the game ["Common"] = 2; -- Can be obtained ["Uncommon"] = 3; -- Can be obtained ["Rare"] = 4; -- Can be obtained ["Epic"] = 5; -- Can be obtained ["Legendary"] = 6; -- Easily obtainable from the highest tier boxes ["Mythical"] = 7; -- Insanely rare ["Unobtainable"] = 8; -- The maximum tier you can get in a box ["Exclusive"] = 9; -- Only limited to a group of people ["???"] = 10; -- One in a kind -- Special Tiers ["Event"] = 11; -- Obtained when you beat certain event ["Achievement"] = 12; -- Obtained when beating achievements ["Special"] = 13; -- Other special items, such as group items etc. } --Standard damage is 25, only really really insanely rare or a few of the selected weapon has bonus damage local tableOfItem = { -- Types of reward: Gold, Item ["Wood Club"] = {tier = "Starter";desc = "We might have stolen something from the local barbarians.";kind = "Weapon";dmg = 25;image = 2263279249}; ["Alpha Sword"] = {tier = "Special";desc = "For people who played during Alpha.";kind = "Weapon";dmg = 25;image = 2263279249}; ["Universal Sword"] = {tier = "???";desc = "The one and only mighty sword, created by WD32##:?#:##DE before universe even existed. Welded by only SpectrumDev himself. +Infinity damage";kind = "Weapon";dmg = 9001;image = 605035383} } function module.GetItem(itemName) print("Starting Module") for Objname, values in pairs(tableOfItem) do if itemName == Objname then return Objname, values end end end function module.TierValue(tierName) for tier, value in pairs(tableOfTier) do if tier == tierName then return value end end end return module
Output:
1 Wood Club
Creating information for panel
Obtaining information for item
Starting Module
Information obtained
Panel already exists
13:32:03.214 - ContentProvider:PreloadAsync() failed for rbxassetid://2263279249
Ending function
2 Alpha Sword
Creating information for panel
Obtaining information for item
Starting Module
Information obtained
Creating new panel
13:32:03.748 - ContentProvider:PreloadAsync() failed for rbxassetid://2263279249
Ending function
Edit: I also need help with the ContentProvider preload async, I have no clue why it don't work.
Is it a problem with the panel placement? The panels seem to have been placed improperly. Here's a suggestion on how you can fix it:
print("Creating information for panel") local horizontal = (i - 1) / 4 local lineNumber = math.floor(horizontal) local Coordinate = UDim2.new(0, 135 * horizontal, 0, 135 * lineNumber)
If lineNumber
should be an integer value starting from 0, you should consider using the math.floor
function.