Network Module v2.3.0 (NM)

Network Module (NM)


(module)

Thanks for your interest in this utility!
Credit to Loleris for their module, Sera, which is incorporated into NM.

NM is designed to make networking in your Roblox game simple, consistent, and efficient.

It supports:

  • RemoteEvents
  • RemoteFunctions
  • UnreliableRemoteEvents

All client-server communication is unified into a single system. A single Wire provides the functionality of all of these.

By default, all communication is passed through a queue and processed sequentially under heavy load. This helps maintain consistent performance and minimize gameplay latency.

(There are two ways to disable this behavior if desired.)

Summary
  • A separate batch table contains the same functions as a normal wire, but executes instantly.
  • The SETTINGS module can be modified to set max lag to zero.

How to Use NM

This module has two sides: Client and Server. These can be retrieved as custom connections, which resolve automatically when available.

Example:

local network = require("./MainModule")

local server = network.Server:Wait()

Once you have a side, create a Wire using a unique name. This name is how the wire is shared between the server and clients.

local network = require("./MainModule")

local server = network.Server:Wait()

local myWire = server.new("MyWire")

Once created, the wire exposes all RemoteEvent, RemoteFunction, and unreliable functionality.


Special Handlers

The Wire object includes additional utilities for advanced or less common use cases.

Serialization (Built-in)

For improved performance, schemas can be used to serialize transmitted data.

(Powered by SERA by Loleris.)

Server example:

local network = require("./MainModule")

local server = network.Server:Wait()

local myWire = server.new("MyWire")

local schemaData = { 
    Test = server.SeraType.String8
}

-- A SeraType can also be provided directly.

myWire:AppendSchema(schemaData)

myWire:FireAllClients({ Test = "Hello!" })

Note: Only the server can call AppendSchema.

Packet Logging

You can log all network traffic on either the client or server.

local network = require("./MainModule")

local server = network.Server:Wait() -- also works on the client

server.record:Connect(print)

-- Equivalent:
server.record:Connect(function(Data)
    print(Data) -- Data is always a table
end)

Logged packet format:

type Data = {
    WireName: string,
    Type: string, -- "Send", "Receive", "Invoke", etc.
    Args: {[number]: any}
}

Unreliable Transfer

Each wire includes an unr table for unreliable communication.

local network = require("./MainModule")

local server = network.Server:Wait()

local myWire = server.new("MyWire")

myWire.unr:FireAllClients("Hello, world!")

Batch Transfer

Each wire includes a batch table for instant execution (bypassing the queue).

local network = require("./MainModule")

local server = network.Server:Wait()

local myWire = server.new("MyWire")

myWire.batch:FireAllClients("Instant transmission!")
myWire.batch:FireAllClients("Instant transmission 2!")
myWire.batch:FireAllClients("Instant transmission 3!")

All calls are sent immediately but are still processed sequentially on the receiving side.


RAW DOCUMENTATION

--[[ 
Objects:
	-- Represents a connection to a wire listener --
	- WireConnection
	
	-- Client-side interface for a wire --
	- ClientWire
	
	-- Server-side interface for a wire --
	- ServerWire
	
	-- Client wire factory and utilities --
	- Client
	
	-- Server wire factory and utilities --
	- Server
	
	-- Signal-based access to Client/Server initialization --
	- NetworkModule


Constructors:
	-- Creates or retrieves a client wire --
	- Client.new(WireName:string, WaitForWire:boolean?) -> ClientWire
	
	-- Creates a server wire --
	- Server.new(WireName:string) -> ServerWire
	

Methods:

	-- Connects to client initialization --
	- NetworkModule.Client:Connect(func:(Client)->()) -> RBXScriptConnection
	
	-- Waits for client initialization --
	- NetworkModule.Client:Wait() -> (Client)
	
	-- Connects a one-time initialization listener --
	- NetworkModule.Client:Once(func:(Client)->()) -> RBXScriptConnection
	
	-- Connects a parallel listener --
	- NetworkModule.Client:ConnectParallel(func:(Client)->()) -> RBXScriptConnection
	

	-- Connects to server initialization --
	- NetworkModule.Server:Connect(func:(Server)->()) -> RBXScriptConnection
	
	-- Waits for server initialization --
	- NetworkModule.Server:Wait() -> (Server)
	
	-- Connects a one-time initialization listener --
	- NetworkModule.Server:Once(func:(Server)->()) -> RBXScriptConnection
	
	-- Connects a parallel listener --
	- NetworkModule.Server:ConnectParallel(func:(Server)->()) -> RBXScriptConnection
	

	-- Connects a listener to the client wire --
	- ClientWire:Connect(Callback:(...any)->()) -> WireConnection
	
	-- Waits for the wire to fire --
	- ClientWire:Wait() -> (...any)
	
	-- Connects a one-time listener --
	- ClientWire:Once(Callback:(...any)->()) -> WireConnection
	
	-- Fires the wire to the server --
	- ClientWire:Fire(...any)
	
	-- Invokes the server and waits for a response --
	- ClientWire:Invoke(...any) -> (...any)
	
	-- Sets the client-side invoke handler --
	- ClientWire:OnInvoke(Callback:(...any)->(...any))
	
	-- Fires unreliable data to the server --
	- ClientWire.unr:Fire(...any)

	-- Fires batched data to the server --
	- ClientWire.batch:Fire(...any)

	-- Invokes batched calls to the server --
	- ClientWire.batch:Invoke(...any) -> (...any)

	-- Fires unreliable batched data to the server --
	- ClientWire.batch.unr:Fire(...any)


	-- Connects a listener to the server wire --
	- ServerWire:Connect(Callback:(Player, ...any)->()) -> WireConnection
	
	-- Waits for a client to fire the wire --
	- ServerWire:Wait() -> (Player, ...any)
	
	-- Connects a one-time listener --
	- ServerWire:Once(Callback:(Player, ...any)->()) -> WireConnection
	
	-- Fires the wire to a specific client --
	- ServerWire:Fire(Player, ...any)
	
	-- Invokes a client and waits for a response --
	- ServerWire:Invoke(Player, ...any) -> (...any)
	
	-- Sets the server-side invoke handler --
	- ServerWire:OnInvoke(Callback:(Player, ...any)->(...any))
	
	-- Permanently removes the wire --
	- ServerWire:Remove()
	
	-- Fires the wire to all clients --
	- ServerWire:FireAllClients(...any)
	
	-- Fires unreliable data to a specific client --
	- ServerWire.unr:Fire(Player, ...any)
	
	-- Fires unreliable data to all clients --
	- ServerWire.unr:FireAllClients(...any)

	-- Fires batched data to a specific client --
	- ServerWire.batch:Fire(Player, ...any)

	-- Invokes batched calls on a client --
	- ServerWire.batch:Invoke(Player, ...any) -> (...any)

	-- Fires batched data to all clients --
	- ServerWire.batch:FireAllClients(...any)

	-- Fires unreliable batched data to a client --
	- ServerWire.batch.unr:Fire(Player, ...any)

	-- Fires unreliable batched data to all clients --
	- ServerWire.batch.unr:FireAllClients(...any)
	
	-- Adds a schema for data optimization --
	- ServerWire:AppendSchema({[string]: SeraType}|SeraType)
	
	-- Removes the schema --
	- ServerWire:RemoveSchema()
	
	
	-- Disconnects the connection --
	- WireConnection:Disconnect()
]]
12 Likes

Awesome project!!! This module is well made and incredibly useful!

1 Like

Quick update! If the model is unavailable on the marketplace, please give me some time. Roblox has flagged this module as “misusing roblox systems,” which is clearly untrue. I have attempted an appeal. Thanks for your patience!

1 Like

Update; fixed this issue. Made a couple changes to the code, and ensured no stray attributes on the module could be flagged as suspicious.

1 Like

UPDATE 2.2.6: Fixed broken .Unr functionality.
I apologize for any issues this may have caused!

1 Like

this is very Promising
might use this over packet since it has sera support

1 Like

Update 2.3.0:
HUGE optimization fixes to NetworkModule!
Reworked queue handling and overflow
several changes throughout the module to increase performance and compatibility without changing the user experience.

I HIGHLY recommend you install this new version of NM!