Table Error [Path is valid but code thinks its not]

So basically I had been debugging for a couple of minutes and find why is it still keeping the errors, here are the new and old code and what it does plus the table

Table

local PlayerDataSample = {
    Stats = {
        Coins = 0;
        Level = 1;
        EXP = 0;
        MaxEXP = 50;
        Class = "Mage"; -- {Mage, Warrior, Tank}
        Quests = 0;
        MaxQuests = 5; -- maximum is 5
        Rank = "Rookie";
        DoubleSword = false;
        Banned = false;
        SpellPoints = 1;
        PhysicalPoints = 1;
        Stamina = 1;
    };

    Equipment = {
        Helmet = "none";
        Armor = "none";
        Pants = "none";
        Boots = "none";
        Sword = "none";
        DualSword = "none"
    };

    Inventory = {
        -- Table for each type

        Armors = {
            Chestplates = {

            };

            Helmets = {

            };

            Pants = {

            };
        };

        Potions = {

        };

        Spells = {

        };

        Weapons = {
            ["Wooden Sword"] = {
                Path = game.ServerStorage.Items.Weapons["Wooden Sword"];
                Damage = 1;
                ClassFor = "Warrior";
                Type = "Sword";
                Rarity = "Common";
                ChanceToGet = 100;
                Physical = 1;
                Spell = 1;
                Upgrades = 0;
                MaxUpgrades = 15;
                Debounce = false;
                CanDamage = false;
                IsTradeable = false;
            }
        };
    };

    Spells = {
        --[[
        ["SPELL_NAME"] = {
            Class = "Mage";
            BaseDamage = 0;
            LevelRequired = 0;
            SellAmount = 0;
            Rarity = "Common";
            ChanceToGet = 0;
            SellAmount = 0;
            IsTradeable = false;
        }
        ]]
    };

    Quests = {
        -- for examples only
        --[[
            ["QuestName"] = {
                IsCompleted = false;
                XPWorth = 0;
                CoinsWorth = 0;
                QuestDescription = "Kill 1 Thing";
                ThingsDone = 1;
                IsFromNPC = "nil"
            }
        ]]
    }
}

New Code
It basically just gets the potions and weapons to clone in the Player’s Backpack instead of one only!

 -- Load Inventory table, gonna refork this a bit so yeah
        for _, PlayerInventory in pairs(PlayerData.Inventory) do
            -- Player Backpacks
            local PlayerStarterGear = Player.StarterGear
            local PlayerBackpack = Player.Backpack

            -- loop all the table
            -- {Weapons, Potions} the only things that can be used as tools
            -- loop all the items inside it

            for _, Tables in pairs(PlayerInventory) do
                for WeaponName, WeaponValue in pairs(Tables.Weapons) do
                    local Weapon = WeaponValue.Path:Clone()
                    Weapon.Parent = PlayerStarterGear

                    local ValuesFolder = Instance.new("Folder")
                    ValuesFolder.Name = "Values"
                    ValuesFolder.Parent = Weapon

                    for WeaponValueName, WeaponsValue in pairs(WeaponValue) do
                        if type(WeaponsValue) == "number" then
                            local Value = Instance.new("NumberValue")
                            Value.Name = WeaponValueName
                            Value.Value = WeaponsValue
                            Value.Parent = ValuesFolder
                        elseif type(WeaponsValue) == "string" then
                            local Value = Instance.new("StringValue")
                            Value.Name = WeaponValueName
                            Value.Value = WeaponsValue
                            Value.Parent = ValuesFolder
                        elseif type(WeaponsValue) == "boolean" then
                            local Value = Instance.new("BoolValue")
                            Value.Name = WeaponValueName
                            Value.Value = WeaponsValue
                            Value.Parent = ValuesFolder
                        end
                    end
                end

                for PotionName, PotionValue in pairs(Tables.Potions) do
                    local Weapon = PotionValue.Path:Clone()
                    Weapon.Parent = PlayerStarterGear

                    local ValuesFolder = Instance.new("Folder")
                    ValuesFolder.Name = "Values"
                    ValuesFolder.Parent = Weapon

                    for PotionValueName, PotionsName in pairs(PotionValue) do
                        if type(PotionsName) == "number" then
                            local Value = Instance.new("NumberValue")
                            Value.Name = PotionValueName
                            Value.Value = PotionsName
                            Value.Parent = ValuesFolder
                        elseif type(PotionsName) == "string" then
                            local Value = Instance.new("StringValue")
                            Value.Name = PotionValueName
                            Value.Value = PotionsName
                            Value.Parent = ValuesFolder
                        elseif type(PotionsName) == "boolean" then
                            local Value = Instance.new("BoolValue")
                            Value.Name = PotionValueName
                            Value.Value = PotionsName
                            Value.Parent = ValuesFolder
                        end
                    end
                end
            end
        end

still it errors and the bug is not fixable for me and I just want this issue to end

Old Code
Basically every tool in one and get’s it’s path and then clones it to the Player’s Backpack and put’s value into it

-- Load Inventory table, gonna refork this a bit so yeah
        for Name, Value in pairs(PlayerData.Inventory) do
            -- Player Backpacks
            local PlayerStarterGear = Player.StarterGear
            local PlayerBackpack = Player.Backpack

            -- loop all the table
            for _, Tables in pairs(Value) do
                -- loop all the items inside it
                local ClonedItem = Tables.Path:Clone()
                ClonedItem.Parent = PlayerStarterGear
            
                local ValuesFolder = Instance.new("Folder")
                ValuesFolder.Name = "Values"
                ValuesFolder.Parent = ClonedItem

                for ValueName, CurrentValue in pairs(Tables) do
                    if type(CurrentValue) == "number" then
                        local Value = Instance.new("NumberValue")
                        Value.Name = ValueName
                        Value.Value = CurrentValue
                        Value.Parent = ValuesFolder
                    elseif type(CurrentValue) == "string" then
                        local Value = Instance.new("StringValue")
                        Value.Name = ValueName
                        Value.Value = CurrentValue
                        Value.Parent = ValuesFolder
                    elseif type(CurrentValue) == "boolean" then
                        local Value = Instance.new("BoolValue")
                        Value.Name = ValueName
                        Value.Value = CurrentValue
                        Value.Parent = ValuesFolder
                    end
                end
            end
        end

Output
Do not even know why this new code does not even work

13:38:41.236 - ServerStorage.Aero.Services.GameStats.Stats:198: invalid argument #1 to 'pairs' (table expected, got nil)
13:38:41.240 - Stack Begin
13:38:41.242 - Script 'ServerStorage.Aero.Services.GameStats.Stats', Line 198 - function PlayerAdded
13:38:41.243 - Stack End

One thing you’ll want to note is that ServerStorage cannot be accessed from a LocalScript; only on the server-side.

but it’s a module that is trying to like be a script so therefore it’s a server module

fixed,

By Dividing the inventory table into 3 parts here is the code for some references

local PlayerDataSample = {
    Stats = {
        Coins = 0;
        Level = 1;
        EXP = 0;
        MaxEXP = 50;
        Class = "Mage"; -- {Mage, Warrior, Tank}
        Quests = 0;
        MaxQuests = 5; -- maximum is 5
        Rank = "Rookie";
        DoubleSword = false;
        Banned = false;
        SpellPoints = 1;
        PhysicalPoints = 1;
        Stamina = 1;
    };

    SetUp = {
        Helmet = "none";
        Armor = "none";
        Pants = "none";
        Boots = "none";
        Sword = "none";
        DualSword = "none"
    };

    Equipment = {
        Armors = {
            Chestplates = {

            };

            Helmets = {

            };

            Pants = {

            };
        };
    };

    Tools = {
        Potions = {

        };

        Weapons = {
            ["Wooden Sword"] = {
                Path = game.ServerStorage.Items.Weapons["Wooden Sword"];
                Damage = 1;
                ClassFor = "Warrior";
                Type = "Sword";
                Rarity = "Common";
                ChanceToGet = 100;
                Physical = 1;
                Spell = 1;
                Upgrades = 0;
                MaxUpgrades = 15;
                Debounce = false;
                CanDamage = false;
                IsTradeable = false;
            }
        };
    };

    Spells = {
        --[[
        ["SPELL_NAME"] = {
            Class = "Mage";
            BaseDamage = 0;
            LevelRequired = 0;
            SellAmount = 0;
            Rarity = "Common";
            ChanceToGet = 0;
            SellAmount = 0;
            IsTradeable = false;
        }
        ]]
    };

    Quests = {
        -- for examples only
        --[[
            ["QuestName"] = {
                IsCompleted = false;
                XPWorth = 0;
                CoinsWorth = 0;
                QuestDescription = "Kill 1 Thing";
                ThingsDone = 1;
                IsFromNPC = "nil"
            }
        ]]
    }
}