Encountering problem with table.insert

Hi! I’ve been encountering an issue while trying a feature. I’m looping through a table and inserting {a table} on another table(lets call it Bob) using

table.insert(Bob, (#Bob+ 1), {Name = "Idk", Value = true}).

But then, when I do print(Bob[1]), it’s printing nil. Can you please help me? Here’s my code :

local Bob = {}

local function sortBasedOnStats()
	print("Clicked") -- This prints out.
	local Pets = script.Parent.MainFrame.PetList:GetChildren()
	for i,v in pairs(Pets) do
		local PetsStat = PetsModule.GetPetStats(v.Name)
		if PetsStat then
			local sum = PetsStat.CoinBooster + PetsStat.AttackBoost + PetsStat.GemBooster
			print(sum) -- This prints out
			PetsStat[#Bob + 1] = {Pet = v, Stat = sum}

Thank you! :smile:

You’re adding the table into PetsStat, not into Bob.


Ur a genius. Well, it happens sometimes xD, been working for 3 hours and I’m tired! Thanks a lot!
Just realized ur my idol ;D

1 Like