Recently, I have been making a ModuleScript that handles the behavior of multiple buttons. However, I started to wonder more about how ModuleScripts work. Do ModuleScripts return a copy of the table in a ModuleScript or point to the table in the module?

For example:

-- ModuleScript
local module = {}

local val = math.random(2, 10)

module.PathToPart = workspace.Part

module.ClearUnnamedParts = function()
	local desc = workspace:GetDescendants()
	for _, descendant in desc do
		if descendant.Name == "Part" then
			descendant:Destroy()
		end
	end
end

return module

-- Does this code get copied whenever required?
-- If not, are there any exceptions, like local variables?

2 comments

1

Point. Kind of like a global variable.

0

Thanks!