Need help inserting a table from a local function into an event’s table. Hard for me to briefly explain.
local function GetItemData(itemData)
local itemPack = {
["Item"] = {
["ItemID"] = 0;
["Config"] = {
["Identity"] = {};
["Modifications"] = {};
["Stats"] = {};
};
};
["Empty"] = true;
};
itemPack.Item.ItemID = itemData.Item.ItemID.Value;
itemPack.Empty = itemData.Empty.Value;
-- Identity
for index, attribute in ipairs(itemData.Item.Config.Identity:GetChildren()) do
if (attribute.ClassName == "ImageLabel") then
local attributePack = {
[attribute.Name] = {
["ImageID"] = attribute.Image;
["ImageColor3"] = tostring(attribute.ImageColor3);
};
};
table.insert(itemPack.Item.Config.Identity, attributePack);
else
local attributePack = {
[attribute.Name] = attribute.Value;
}
table.insert(itemPack.Item.Config.Identity, attributePack);
end
end
return itemPack
end
-- Public Methods
function SaveInventory(player)
local playerUserID = PlayersService:GetUserIdFromNameAsync(player.Name)
local itemInventoryStorage = DataStoreService:GetDataStore(playerInventoryDataName);
local inventory = PlayersService:FindFirstChild(player.Name).PlayerData.CharacterData.Inventory
local newInventory = CreateInventoryPack(inventory);
-- Set data store key
local setSuccess, errorMessage = pcall(function()
itemInventoryStorage:SetAsync(playerUserID.."/Inventory", newInventory)
end)
if not setSuccess then
print("Saving Inventory Unsuccessful...");
warn(errorMessage);
else
print("Inventory Saved!");
end
end
function CreateInventoryPack(inventory)
local inventoryPack = {
["Equipped"] = {
["Equipment"] = {};
["Tools"] = {};
};
["Stored"] = {
["Equipment"] = {};
["Quest"] = {};
["Resources"] = {};
["Tools"] = {};
};
};
-- Equipped
local items = inventory.Equipped.Equipment:GetChildren()
for index, item in ipairs(items) do -- Equipment
table.insert(inventoryPack.Equipped.Equipment, GetItemData(item));
end
print(inventoryPack)
return inventoryPack;
end
Apologies for uploading so much, but I can’t really tell what I should and shouldn’t show y’know.
I’m running into an issue where [1] shows up instead of [string : tableObject.Name] or whatever–every time I try to create a new list using a local function it returns with the index instead of the name.
{
["Equipped"] = ▶ {...},
["Stored"] = ▼ {
["Equipment"] = ▼ {
[1] = ▼ {
["Empty"] = true,
["Item"] = ▼ {
["Config"] = ▼ {
["Identity"] = ▼ {
[1] = ▼ {
["ClassType"] = ""
},
[2] = ▶ {...},
[3] = ▶ {...},
[4] = ▶ {...},
[5] = ▶ {...},
[6] = ▶ {...}
},
["Modifications"] = ▶ {...},
["Stats"] = ▶ {...}
},
["ItemID"] = 0
}
},
[2] = ▶ {...},
[3] = ▶ {...},
[4] = ▶ {...},
[5] = ▶ {...},
[6] = ▶ {...},
[7] = ▶ {...},
[8] = ▶ {...},
[9] = ▶ {...},
[10] = ▶ {...},
[11] = ▶ {...},
[12] = ▶ {...},
[13] = ▶ {...},
[14] = ▶ {...},
[15] = ▶ {...},
[16] = ▶ {...},
[17] = ▶ {...},
[18] = ▶ {...},
[19] = ▶ {...},
[20] = ▶ {...},
[21] = ▶ {...},
[22] = ▶ {...},
[23] = ▶ {...},
[24] = ▶ {...},
[25] = ▶ {...},
[26] = ▶ {...},
[27] = ▶ {...},
[28] = ▶ {...},
[29] = ▶ {...},
[30] = ▶ {...}
},
["Quest"] = ▶ {...},
["Resources"] = ▶ {...},
["Tools"] = ▶ {...}
}
How would I be able to fix this so that the first [1] to [9] would instead be [01] to [09] like their names, and the second [1] would instead be [ClassType].
Any help would be greatly appreciated!
Please let me know if I should recreate the concept with a simplified example!