This is a custom lightweight framework for Roblox games that simplifies communication between scripts (similar to Knit). It also improves workflow by simplifying frequent lines of code.
It's organized by two types of script: services and controllers, for server and client respectively.
-
Integrated functions:
service.Init()for setting up initial variables (yields)service.Start()for main tasks in a scriptservice.PlayerSetup(player: Player)when player joins, which runs first across all scripts (yields)service.PlayerAdded(player: Player)when player joins
-
Optional functions:
service.Step(dt: number)for the main RunService.Stepped loop in a scriptservice.RenderStep(dt: number)for the main RunService.RenderStepped loop in a scriptservice.CharacterAdded(player: Player)when any character is addedservice.PlayerRemoving(player: Player)when player leavesservice.BindToClose()when the server is shutting down
Modules can be obtained by service.modules.ModuleName, where ModuleName is an uniquely named module in ReplicatedStorage.SharedModules or ServerScriptService.Modules
- Script names are always PascalCase
- Components and methods of a module / table are always PascalCase
- Service / controller / module variables are always PascalCase
- Other variables are always camelCase
Naming convention: ____Service (e.g, EnemyService, UnitService, etc...)
Overview:
- Services are server scripts located inside ServerScriptService.Scripts
- Other services can be obtained by
service.framework:Get("ExampleService")in service.Init - Functions in other services (e.g
function service.Update(...)in ExampleService) can be called byExampleService.Update(...) - Controllers can be obtained by
service.framework:Fetch("ExampleController")in service.Init
Remotes:
- Service functions that can be called from the client (remotes) are in service.Client
function service.Client.ExampleFunction(player: Player, ...) end
- Remotes can be called from controllers as follows:
ExampleService.ExampleFunction:Fire(...) local output = ExampleService.ExampleFunction:Invoke(...) --//Yields
Example:
--[[ExampleService]]
service = {Client = {}}
--//Initialize variables
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Initialize services, controllers, and modules INLINE
local CurrencyService
local ExampleController
local ExampleInfo
function service.Init()
--//Define controllers, services, and modules by their script name
CurrencyService = service.framework:Get("CurrencyService")
ExampleController = service.framework:Fetch("ExampleController")
ExampleInfo = service.modules.CurrencyInfo
end
--//Remotes
function service.Client.Click(player: Player, ...)
return true
end
--//Main
function service.ExampleFunction(...)
end
function service.PlayerAdded(player: Player)
task.wait(2)
ExampleController.Replicate:Fire(player)
end
function service.Start()
service.ExampleFunction()
CurrencyService.ExampleFunction()
end
return serviceNaming convention: ____Controller (e.g, EnemyController, UnitController, etc...)
Overview:
- Controllrs are client scripts located inside StarterPlayer.StarterPlayerScripts.Scripts
- Other controllers can be obtained by
service.framework:Get("ExampleController")in service.Init - Functions in other controllers (e.g
function service.Update(...)in ExampleController) can be called byExampleController.Update(...) - Services can be obtained by
service.framework:Fetch("ExampleService")in service.Init
Remotes:
- Controller functions that can be called from the server (remotes) are in service.Server
function service.Server.ExampleFunction(...) end
- Remotes can be called from services as follows:
ExampleController.ExampleFunction:Fire(player, ...) ExampleController.ExampleFunction:Fire(playerTable, ...) ExampleController.ExampleFunction:FireAll(...)
Example:
--[[ExampleController]]
service = {Server = {}}
--//Initialize variables
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Initialize controllers, services, and modules INLINE
local CurrencyController
local ExampleService
local ExampleInfo
function service.Init()
--//Define controllers, services, and modules by their script name
CurrencyController = service.framework:Get("CurrencyController")
ExampleService = service.framework:Fetch("ExampleService")
ExampleInfo = service.modules.ExampleInfo
end
--//Remotes
function service.Server.Replicate(...)
print("Replicated")
end
function service.Start()
local output = ExampleService.Click:Invoke()
end
return service