Tables inside a for pairs loop is considered a function

Hello! Apparently, this table considers another table a function however it is not. It’s so agitating to handle when it makes no sense for me to even understand why it’d fail.

So I came here to ask for help, and why is this happening, I’ve tried to look for solutions and even remade the whole code, still thinks it is a function.

function CraftingModule.Craft(Table: any)
	local PermissionAllowed = false	
	local CraftedName = nil;
	for CraftName, CraftTable in pairs(CraftingModule) do
		local RequiredToBeAccepted = 0;
		for ItemName, ItemObject in pairs(CraftTable) do
			RequiredToBeAccepted +=1
		end
		
		local AcceptedTimes = 0;
		for TableName, TableRequired in pairs(CraftTable) do
			for TableName2, TableRequired2 in pairs(Table) do
				if(TableName2:lower() == TableName:lower() and TableRequired2 == TableRequired) then
					AcceptedTimes +=1
					break
				end
			end
		end
		
		if(AcceptedTimes >= RequiredToBeAccepted) then
			CraftedName = CraftName
			PermissionAllowed = true
			break
		end
	end
	
	if(PermissionAllowed and CraftedName ~= nil) then
		return true, CraftedName;
	else
		return false, nil
	end
end

return CraftingModule

I’d appreciate the help! :wink:

You’re iterating the same module? Why not just separate crafting blueprints (or whatever it’s called) on a separate table? If you loop through the module, not only you are getting tables, you are also getting any other value.

If I understand how you want your module to be written, printing the key and value of the module might say this:

Planks table
Door table
Craft function -- you just tried to index something in a function.
Glass table

Oh wow! Thank you for the help, that seem to do the trick, I’m not fully aware of how modules work quite yet, however I understand most of the basic knowledge of it. Thank you for helping me out, I guess I need to avoid using tables that are already being looped inside a pairs loop from another function. Thanks! :happy3:

1 Like