Hello, I have a table that has multiple tables inside of it. I want to save specific objects to the table and I was able to do this with If statements but I feel like there is a way I can make this more flexible but I don’t know how.
Main code:
local SectionTable = {
S1 = {};
S2 = {};
S3 = {};
S4 = {};
}
local function AddItemToTable(plr,obj)
local objType = Module[obj.Name]["Type"]
local objName = obj.Name
local S1Table = SectionTable.S1[plr.Name]
local S2Table = SectionTable.S2[plr.Name]
local S3Table = SectionTable.S3[plr.Name]
local S4Table = SectionTable.S4[plr.Name]
if obj == S1Table[objName] or S2Table[objName] or S3Table[objName] or S4Table[objName] then
if objType == "S1" then
S1Table[objName] = S1Table[objName] + 1
elseif objType == "S2" then
S2Table[objName] = S2Table[objName] + 1
elseif objType == "S4" then
S4Table[objName] = S4Table[objName] + 1
elseif objType == "S3" then
S3Table[objName] = S3Table[objName] + 1
end
else
if objType == "S1" then
S1Table[objName] = 1
elseif objType == "S2" then
S2Table[objName] = 1
elseif objType == "S4" then
S4Table[objName] = 1
elseif objType == "S3" then
S3Table[objName] = 1
end
end
end
Module Layout:
["Sword"] = {
Name = "Sword";
Type = "S1";
Model = EquipmentModels.Sword;
Desc = "sword";
};