Workspace.Part.ModuleScript:3: attempt to index local 'part' (a nil value)

Situation:

--serverscript
local part = script.Parent
local module = require(script.Parent.ModuleScript)
module.activate(part)
--modulescript
local module = {}
function module:activate(part)
	print(part.Name)
end
return module

Output:
14:06:37.839 - Workspace.Part.ModuleScript:3: attempt to index local ‘part’ (a nil value)
14:06:37.840 - Stack Begin
14:06:37.841 - Script ‘Workspace.Part.ModuleScript’, Line 3 - field activate
14:06:37.841 - Script ‘Workspace.Part.Script’, Line 3
14:06:37.842 - Stack End

I used print(Part) in both script and module script, and it prints Part from script, but nil from module script.
How can I fix this error?

You’re defining the function with a : but calling it with a .

Since it’s not gonna be a method of an instance just use .

a:b(...) is just syntax sugar (a nicer way to write something) for a.b(a, ...), so module:activate(part) is the same as module.activate(module, part)

2 Likes

Not sure, but try

module:activate(part) --in the server script
1 Like

When naming functions in modules make sure they are in the brackets {} and use a dictionary idk what it’s called to name it

local module = {
["activate"] = function(part)
	print(part.Name)
end;
}
return module

this isn’t necesary, what you said is equal with

local module = {}
module.activate = function(part)
	print(part.Name)
end
return module
4 Likes

I did not know that, thank you for explaining.

1 Like

Oh well, I should have tried using a column. For those who replied, thank you for answering my question.