So, do you know this instance called modulescripts? It’s very useful to development but it’s not as magical as you think, this tutorial is not about how to use them but how they work.
So a quick start, when you create a modulescript and open it this should appear.
local module = {}
return module
yeah. Now at most module scripts(well, all) you will see something like this
local module = {}
function module.Print(string)
print(string)
end
return module
What does this module.print do? Your just assigning a function to the module table. Proof? Here.
local module = {
Print = function(string)
print(string)
end
}
return module
And yes it works the same way, but why do we do function module.yourfunction instead? Because it’s much cleaner and you can replace the dot with : unlike the proof method.
Which can return self.
Now, what does require do, really? When you call require on a modulescript it just returns a table from the module script. Simple right?
This is also the same with variables, you can also try it in a normal script
Before this ends, after I heard all of this, are modulescripts still useful?
The answer is yes. Because you can reuse functions so you’d don’t have to rewrite them.
In short, require just returns the table from the modulescript which contains functions and variables
Well, I hope you learned something.
also ik it’s extremely short but there’s really nothing else to say about them