#Module vs script

1 messages · Page 1 of 1 (latest)

maiden hinge
#

So im a new scripter trying to learn everything i can. I see some developers using module scripts but i dont understand it. Can someone explain it??

little reef
#

If you ignore ModuleScripts, you’re basically choosing to stay a beginner longer than necessary.

What a ModuleScript actually is:
A ModuleScript is a script that stores functions or data and then returns it so other scripts can use it.

Think of it like this:

  • Normal Script = does stuff immediately
  • ModuleScript = stores logic for reuse

Core idea:
A ModuleScript must return something at the end:
return something

Another script uses it like this:
local thing = require(module)

Example:

ModuleScript (DamageModule):
lua local DamageModule = {} function DamageModule.DealDamage(player, amount) print(player.Name .. " takes " .. amount .. " damage") end return DamageModule

Normal Script:
lua local DamageModule = require(game.ServerScriptService.DamageModule) DamageModule.DealDamage(player, 20)

Why developers use ModuleScripts:

  • Reuse code instead of copying
  • Keep code organized
  • Update logic in one place
  • Build proper systems instead of messy scripts

Real use cases:

  • Combat systems
  • Inventory systems
  • Data saving
  • Utility/helper functions

Common beginner mistake:
Using a ModuleScript without returning anything:
lua print("Hello")
This is useless.

Mental model:

  • Script = worker
  • ModuleScript = toolbox

Workers grab tools when needed.

floral harness
#

ok who am i kidding