Trying to count the elements from a table always returns 0

I have the following code in a ModuleScript, for a tutorial. It works fine to pull data from it. My problem is that trying to count the amount of items inside the table always returns 0. Did I do something wrong with the formatting of the table?

-- ModuleScript
local tutorial = {
	["1"] = {
		["Title"] = "Test";
		["Content"] = "David sucks at editing these c:<";
		["Beam"] = {script.TutorialBeam,,10,0)};
	["2"] = {
		["Title"] = "Test #2";
		["Content"] = "it works!";
		["Beam"] = {script.TutorialBeam,,5,35)};

return tutorial
-- LocalScript
local function beginTutorial()

	tutorialWindow.Visible = true

	local index = 0
	local maxIndex = #tutorialStages
	print(maxIndex) -- This always prints out as 0, regardless of the amount of items inside the table

		index += 1
		local step = tutorialStages[tostring(index)] -- This actually works.

Thanks in advance!

tutorialStages presumably does not contain integer indices. The unary length operator on tables only account for integer indices starting at 1.

"1" (as a string) isn’t considered an integer by Lua(u). Is there any reason why you’re using the string "1" as the index rather than the numeric 1?

1 Like