Single Script Architecture and Modular Programming

Hello everyone.
I would like to show and explain some of the types of scripting organizational methods to newer folks joining Luau and Roblox!

What is a module? (For newer folks)

Modules are simply an instance that can be created within your game. Simply create a new instance and search for ModuleScript and boom! You have a module.

Modules are mainly used through a function called require, which takes a parameter require(path). E.g. require(game.ReplicatedStorage.ModuleScript) would grab the code from inside of the instance and import it into your current script allowing you to utilize it. (The code is ran, whatever is returned is used in your current script, hence why you return the value or table)

--// ModuleScript
--// Path: game.ReplicatedStorage.MyModule
local module = {}
module.Hello = "World"

function module.World()

return module --// We return our table.
--// Main Script
local RStorage = game:GetService("ReplicatedStorage")
local MyModule = require(RStorage.MyModule) --// The code is retrieved through a table that MyModule returns!


Modular Programming

Modular Programming simply utilizes both external and internal modules that assist with the main applications of your game/frameworks. This allows for a more preferred organizational method, which essentially splits your system into more “sub-systems”. The entire purpose of this method is for re-usability of code.

To explain this a bit more. Imagine you have all your functions and values inside your script, your script becomes a total of 500+ lines of code and is looking pretty messy. Turn your functions into modules and require them!

--// Module
return function(message)

--// Script
local PrintFunction = require(
PrintFunction("Hello World!")

Anything can be returned through a module!
I highly recommend not using this specifically for a ton of functions. Rather use this programming style to recycle your functions. E.g. creating utilities to use in multiple scripts.

Single Script Architecture

SSA(Single Script Architecture) is simply what the name implies. Everything is contained within one script. While this method is completely fine, it can become quite tedious at larger amounts of code.

local System1 = {}
local System2 = {}

  self = System1
  self.Cookie = "Chocolate"

  self = System2
  self.Chocolate = "Cookie"

print(System1.Cookie, System2.Chocolate)
--// Returns: Chocolate Cookie

This is one of the many ways to organize SSA. While I do prefer this one there are other very simple ones like splitting your code into functions. This is another type of programming called Functional Programming. Which is simply splitting your code into functions for a more clean system. There also is another form of highly used programming called Object Orientated Programming, which I won’t be covering, but take a look at it!.

For any advanced or beginner users who are curious about the differences between the following. See below

  • Procedural Orientated Programming
  • Object Orientated Programming
  • Functional Orientated Programming
  • Modular Programming


Look at all the resources available → Search results for 'Object Orientated Programming' - Developer Forum | Roblox

1 Like

While true, it’s not the most accurate application of the term. Single script architecture for Roblox development generally implies a high degree of modularity. It boasts a single point of entry for your server and client (one Script, one LocalScript) while 100% of the other work is done in ModuleScripts.

Containing absolutely everything in one script does technically classify as single script architecture but we refer to that as monolithic scripts. Monolithic scripts are unreadable, unmaintainable and present issues with the Script Editor (sometimes it can become very laggy).


Thank you for the correction. Ill fix this post once im online. Completely forgot to specify its application on server and client bounds. I will probably add in a bit more clarification about the script I wrote for SSA, including the term monolithic scripts.

I always had questions about single-script architecture.

What are the benefits of it?

Will it be good for me, if I want to load ‘‘this’’ script earlier than others? Like, I want to run my Data script earlier and then run the other scripts.

How my module scripts should look like, how can I handle my remote events connections in module scripts and other signal connections?

I saw many posts about SSA, but I’m still thinking about it. I have good experience in structuring and organizing games, but, keeping in server and local scripts makes me confused. Modular trees look beautiful for me in my opinion. So, still have the questions, mentioned in my message at start. I want to know better about Single-Script Architecture.

1 Like