How To Use Module Scripts In A Nutshell

After a bit of messing around I made a really simple explanation of module scripts, I just realized how easy they are to use and they are already saving me more time than I spent writing this.

Step 1: Throw a module script on the client end (ReplicatedStorage) or server end (ServerScriptService).

Step 2: Put anything you want inside it, as long as it follows the following format:

local module = {}

function module.FunctionName(VariablesHere)
   --Insert code here!
end

return module

Step 3: Make a variable requiring the module.

local module = require(game:GetService("ReplicatedStorage").ModuleScript)
--or
local module = require(game:GetService("ServerScriptService").ModuleScript)

Step 4: Call the function in the module from the script.

local module = require(game:GetService("ReplicatedStorage").ModuleScript)

module.FunctionName(VariablesHere)

Simple, time saving, lag reducing, these things are cool. I know someone already probably posted something similar, I am just excited to be learning so much about scripting!

You can find more information about module scripts here and here, this is also cool

9 Likes