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

In module scripts, why don’t people put the functions inside the table’s brackets?

So looking in other players’ module scripts, I always see people do something like this:

local module = {}

local function module.newFunc()
      
      —code

end

But why don’t people do this?


local module = {

    function newFunc()

          —code

    end


}

I heard somewhere that putting it inside the brackets is messy and inefficient, but i don’t see how. Any help?

1 answer

They both work but it mostly depends on which one you would prefer.

These are basically the same.

local module = {}

module.PrintPlayers = function()
	for i,v in ipairs(game.Players:GetPlayers()) do
		print(v)
	end
end

return module

and

local module = {


PrintPlayers = function()
	for i,v in ipairs(game.Players:GetPlayers()) do
		print(v)
	end
end
	

}
return module

In the first one you assign the function inside that table but in the second one it's already assigned just by putting the function inside the table.

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