Learning OOP, tried requiring this and i dont know how.
Any idea on how to require this?
local module = {}
local plrs = game.Players
function module.plrs:GetPlayers(plrname)
print(self.Name)
end
return module
nothing prints
Learning OOP, tried requiring this and i dont know how.
Any idea on how to require this?
local module = {}
local plrs = game.Players
function module.plrs:GetPlayers(plrname)
print(self.Name)
end
return module
nothing prints
When you write the module script, get a normal script then write require()
and include directory to the module script. Preferably inside ServerScriptService
, a service canonically for scripts. Essentially as it says in the name, it’s a module containing the code.
I did that yesterday and it didnt work
You can use require()
for loading functions from module script.
Example:
Module Script
local module {}
function module.prnt()
print("abc")
end
return module
Normal Script
local module = require(path_to_modulescript)
module.prnt() -- It should print "abc" on console
On another note:
The module is most likely to error because module.plrs
is nil. Since plrs
is a local variable, rather than module variable. Also this is still not OOP yet, as most OOP are written using metatables
.
module.plrs
= nil
require
function to get the returned value of the module, aka the module which is a table
Also, this is not OOP. This is just module script code.