"attempt to call nil value" when the parameters are indexed arrays with stringVals

local playerCaptureTable = {}

local blueRoster = serverStorage.GameValues.BlueTeamRoster:GetChildren()
local redRoster = serverStorage.GameValues.RedTeamRoster:GetChildren()

print ("blueRoster : ")
print (blueRoster) --shows it has items
print ("redRoster : ")
print (redRoster)--shows it has items too


	if blueRoster and #blueRoster >= 1 and redRoster and #redRoster >= 1 then --has no problem passing this test

		local combinedRostersTable = module.CombineTables(blueRoster, redRoster)--this comes up "attempt to all nil value"

the above code is in a module on the Server:

  1. there are stringvals in a folder in server storage. it grabs all those and makes an indexed array of them (blueRoster)
    2)it does the same thing with a second folder, and makes a second array. (redRoster)
  2. it WOULD call a function within the same module to combine them - but never calls the function (print statements show it isn’t called) and that line gives us a “attempt to call nil value” error…

there are definitely occupants in both rosterfolders (checked it)

AND print statements also show my tables are occupied (not nil)

Also, all my StringVals are pre initialized (not nil)

Any idea what is happening? I’ve been troubleshooting this like mad
Thx!

1 Like

The error seems to indicate the module has no field named CombineTables to call. Everything else you’ve already troubleshot.

2 Likes

hm. but I do :slight_smile:

but i do but i do (min chars)

thx!

1 Like

Are you sure it’s the correct module? Or that the module actually returns a table with that method? Or that the function is not spelled differently (caps)? If that’s the erroring line then CombineTables is nil.

EDIT. @SodaCanBros just a moment!

In case the function is defined in this same module, then it might error because of being defined afterwards.

local module = {}
module.DoSomething() -- not yet!
function module.DoSomething() end
2 Likes

all good points, and thank you!

Sadly, it’s spelled correctly (it greyboxes if I double click it, in both spots)

It’s also in the same module and ABOVE the function call. not below.

i still have no idea?

1 Like

here is the CombineTables function - is there some reason it is returning nil that I don’t see?:

function CombineTables(table1, table2)
	local FinalTable = {}
print("inside combine tables 214")
	if table1 and #table1 >= 2 then
		for i,v in pairs(table1) do
		    table.insert(FinalTable,v)
		end
	elseif table1 and #table1 == 1 then
print("	elseif table1 and #table1 == 1 then")
		table.insert(FinalTable,table1[1])
	end
	if table2 and #table2 >= 2 then
		for i,v in pairs(table2) do
		    table.insert(FinalTable,v)
		end
	elseif table2 and #table2 == 1 then
		table.insert(FinalTable,table2[1])
	print("	elseif table2 and #table2 == 1 then")
	end
print("FinalTable")

print(FinalTable)

return FinalTable

end

incidentally, none of these print statements fire, because it never calls the function?

1 Like

oh i see it now! I need:

function module.CombineTables(table1, table2)

the “module.” is missing in mine …

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.