Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Module script for tables?

Module Script:

local BigTable = {
	
	moveAble = {
		"Land",
		"Cliff",
		"Ramp",
	},
}
return BigTable

I get this in the output:

attempt to index local 'moveAble' (a nil value)

I wanted to make a my main script smaller by putting all my tables into a module script, but I'm having some trouble

local BIG = require(game.Workspace.Tables)

local moveAble = BIG[1]
print(moveAble[1])--nil???

Why is it nil? Shouldn't the require return the big table?

1 answer

✓ Accepted answer

Arrays and dictionaries

The problem is how you're indexing your required module vs what format it's in. It's very important to know the difference between array styled tables, and dictionary styled tables. If you want to know more about how these table formats work, you can see this answer I've given: https://scriptinghelpers.org/questions/28182/how-to-learn-tables#31632

Solution

The solution is simple. Your module is in dictionary format, so that means all of it's keys are non-numeric, and defined. You simply just need to index your module for the defined key. In this case, "moveAble"

local BIG = require(game.Workspace.Tables)

local moveAble = BIG.moveAble -- Index the dictionary for the defined key: "moveAble"
print(moveAble[1])

Hope this helped, let me know if you have any questions.

This discussion is preserved as it was. New answers, comments, and votes are closed.