Module Functions

Hi, im trying to pass some values in module but it keep printing unexpected stuff.
Here is my code (Not module script)
local plrlist, nonPlrList, AllCharList = DTModule:PlayersInRange(bullet.Position, 12)
(Module script)

local module = {}
 
function module.PlayersInRange(Origin, range)
	local plrlist, nonPlrList, AllCharList = {}, {}, {}
	print(Origin) --prints {["PlayersInRange"] = "function", ["ShowDmg"] = "function"}
end

return module

why is the first valie (Origin) not vector3 (Bullet.Position)?

When you use module:Function() when module.Function() is written, the first value is self, the same table as the module, call it as it is originally written

module.PlayersInRange(Origin, range)

or ignore the first value

function module.PlayersInRange(_, Origin, range)

Replace this

With this:

local plrlist, nonPlrList, AllCharList = DTModule.PlayersInRange(bullet.Position, 12)

The reason is that in the module script the function is: module.PlayersInRange() and not module:PlayersInRange()

1 Like