While passing a large dictionary as an argument function tells its nil

I have a function that returns me the length of a dictionary and it all worked fine when the dictionary was small (the dictionary is a world map that scripts use to then generate it) but now that I made it bigger the function just returns nil. I have a function to generate structures and it also uses the dictionary. But here it works fine and I can print it but in my len() function it returns nil.

len() function:

-- Returns length of dict (int)
local function len(dict)
	local length = 0
	for _ in pairs(dict) do
		length += 1
	return length

Generate structures:

function chunkSystem:generateStructures(amount, worldTable)
	chunkInfo = {
		[1] = chunk
		[2] = chunkOrientation
		[3] = biomeName
	local mapSize = (len(worldTable)-1)/2
	for i = 1, amount do
		local chunkInfo = worldTable[tostring(math.random(-mapSize, mapSize))][tostring(math.random(-mapSize, mapSize))]
		local structureBiome, biomeName = structureData[chunkInfo[3]], chunkInfo[3]
		local structureName = randomDict(structureBiome)

		chunkInfo[1] = game.ReplicatedStorage.StructureModels[biomeName][structureName]
		chunkInfo[2] = getRandomChunkAngle()
		chunkInfo[3] = biomeName

Can you please add a print() statement before the local mapSize = (len... bit, that outputs the whole dictionary, then SS it here so we can understand where the issue is occuring

1 Like

Name len is very misleading, try to rename it to be sure it’s not a reserved function or a shortcut for string.len. I’d suggest you trying a debug in Roblox Studio so you can see if your dictionary is not null.
It’s better to provide us full debug stack in the future so we don’t have to guess where is the problem.

1 Like

Sorry and thank you, I’m pretty sure it was the name since when I changed it, all worked.