Question regarding Modules

I’m not sure whether or not this needs to be added, but I felt like I should. You can attach functions to tables anyways without a ModuleScript. The definition of a ModuleScript is not “a table with functions attached”. It is “a Lua source container that runs once and must return exactly one value.

local foo = {
	bar = function()
		print('baz')
	end,
}

foo.bar2 = function()
	print('baz2')
end

foo.bar()
foo.bar2()

The reason, however, that ModuleScripts are so commonplace is because they make organization & not repeating yourself incredibly simple. A thread that I recommend you learn with alongside teaching ModuleScripts to yourself is this one:

This thread will do a good job walking you through attaching functions to tables & then why integration with ModuleScripts is so important.

3 Likes