Missing Argument in Table #2?

Trying to code game leaderstats so I don’t have to worry about it but this issue I think is hard for me and yes I am using the Aero DataStore System so that’s the reason there is an path named with Aero so is there a solution for this table error?

Code:

if not table.find(PlayerData.Inventory, Names) then table.insert(PlayerData.Inventory, Names) end

Error:

15:41:46.174 - ServerStorage.Aero.Services.GameData.Stats:271: missing argument #2
15:41:46.175 - Stack Begin
15:41:46.178 - Script 'ServerStorage.Aero.Services.GameData.Stats', Line 271 - function PlayerRemoved
15:41:46.179 - Stack End

still In need of an reply don’t know what issue is causing this

Hello

This error can only happen if the second argument is nil. So try checking the value of “Names” and printing it before the statement.

1 Like

here is a reference of it:

local function PlayerRemoved(Player)
        local Data = DataModule.ForPlayer(Player)

        local success, PlayerData = Data:Get("PlayerData", PlayerDataSample):Await()
        if (success) then
            print("Data was Successfully Retrieved!")
        else
            warn("Failed to Retrieve Data!")
        end

        -- for Inventory Saving
        for Names, Objects in pairs(Player.StarterGear:GetChildren()) do
            if not table.find(PlayerData.Inventory, Names) then table.insert(PlayerData.Inventory, Names) end

            for _, ChildrenObjects in pairs(Objects:GetChildren()) do
                if ChildrenObjects:IsA("Folder") then
                    for Name, Values in pairs(ChildrenObjects:GetChildren()) do
                        --[[
                            String = ""
                        ]]
                        local NormalTable = table.find(PlayerData.Inventory, Objects.Name)

                        table.insert(NormalTable, {Name = Values})
                    end
                end
            end
        end

Hello

There is no such thing as “StarterGear” under the play. Its called the backpack.
If you put tools inside startergear in studio then it will be parented to every player under backpack.

So in the for loop try changing the Player.StarterGear to Player:WaitForChild(“Backpack”).

1 Like

if this is the solution mark HawDevelopment’s comment above this one
Just for Clarity
StarterGear is not a Child of Player since it is not a Child of Player the “Names” variable will always return nil and since it is nil, that’s where you get the error so just change

Player.StarterGear:GetChildren()

With

Player:WaitForChild("Backpack"):GetChildren()
1 Like

cc @starnova224 and @HawDevelopment

To Add


  • StarterGear is starter pack but for the player itself only
  • WaitForChild is not needed since this is when the player Leaves
  • GetChildren is already used in the piece of code I gave

The Solution was all along with @HawDevelopment’s Backpack but I also changed table.find which is very inefficient and ill leave a link here just ot prove and get no hate, this took me a long time just to figure it out lol

1 Like