NetRay 2.0 - Advanced Roblox Networking Library
Overview
NetRay is a powerful, optimized networking library for Roblox that significantly enhances RemoteEvents and RemoteFunctions with advanced features such as batched events, event prioritization, automatic compression, and circuit breaker protection.
Why Use NetRay?
Performance & Efficiency
NetRay improves memory usage and reduces network overhead by compressing data before transmission. It supports two types of compression:
- Run-Length Encoding (RLE) ā Ideal for repetitive data sequences.
- Lempel-Ziv-Welch (LZW) ā Great for general data compression.
By batching multiple events together and compressing payloads, NetRay reduces bandwidth consumption and improves game responsiveness. This leads to less lag and more efficient networking.
Key Features
- Intuitive API: Designed to feel like standard Roblox RemoteEvents, making it easy to learn and use.
- Promise-based Requests: Simplify asynchronous communication with a built-in Promise implementation.
- Typed Events: Enforce type checking for event arguments using Luau types.
- Automatic Compression: Optimize network traffic for large data payloads with automatic compression.
- Circuit Breaker Pattern: Prevent cascading failures by temporarily disabling problematic events.
- Event Prioritization: Prioritize critical events to ensure they are processed first.
- Event Versioning: Maintain backward compatibility with versioned events.
- Batched Events: Reduce network overhead by batching frequent small events.
- Middleware Support: Add custom logic to event handling with middleware functions.
- Comprehensive Metrics: Track network performance with detailed metrics and analytics.
- Secure Events: Ensure secure event handling with server-side verification.
- Documentation Generator: Automatically generate documentation for all registered events and request handlers.
- Binary Encoding/Decoding: Automatically Encodes and decodes compressed data to save more bandwidth and ping
Screenshots & Results
NetRay reduces bandwidth usage significantly in high-frequency event scenarios. Below are results from testing, firing an event every 0.01 seconds with an 8 KB payload:
Roblox Default:

NetRay:
Links
- GitHub: GitHub - AstaWasTaken/NetRay: A powerful, optimized networking library that provides advanced tools while maintaining the familiar feel of standard Roblox RemoteEvents.
- Roblox: https://create.roblox.com/store/asset/73402828830476/NetRay
Getting Started
Installation
To include NetRay in your project:
- Copy
NetRay.lua
into your game. - Place it in ReplicatedStorage.
- Require the module in your scripts:
local NetRay = require(game:GetService("ReplicatedStorage").NetRay)
Usage
Server ā Client Communication
Firing an Event to a Single Client
NetRay:FireClient("EventName", player, arg1, arg2)
Firing an Event to All Clients
NetRay:FireAllClients("EventName", arg1, arg2)
Firing an Event to a Group of Clients
NetRay:FireClients("EventName", {player1, player2}, arg1, arg2)
Example
NetRay:RegisterEvent("ShowNotification")
NetRay:FireClient("ShowNotification", player, "Hello, World!")
Customising and Registering a Event
NetRay:RegisterEvent("PlayerJoined", {
rateLimit = 100, -- Events per minute
throttleWait = 0.1, -- Minimum time between events
priority = NetRay.Priority.HIGH, -- Event priority
typeDefinitions = {"string", "number"}, -- Enforce argument types
batchable = true -- Allow batching
})
Client ā Server Communication
Sending an Event from Client to Server
NetRay:FireServer("EventName", arg1, arg2)
Example
-- Server
NetRay:RegisterEvent("PlayerJumped")
NetRay:RegisterRequestHandler("PlayerJumped", function(player, height)
print(player.Name .. " jumped " .. height .. " studs!")
end)
-- Client
NetRay:FireServer("PlayerJumped", 10)
Request/Response (Advanced Networking)
Client Requesting Data from Server
NetRay:RequestFromServer("GetPlayerStats"):andThen(function(data)
print("Received stats:", data)
end):catch(function(error)
print("Request failed:", error)
end)
Server Handling the Request
NetRay:RegisterRequestHandler("GetPlayerStats", function(player)
return {
health = 100,
level = 5
}
end)
Batched Events (Optimizing Network Traffic)
NetRay can batch multiple events together to reduce the number of RemoteEvent calls.
Enabling Batching
NetRay:RegisterEvent("DamagePlayer", {batchable = true})
NetRay:FireServer("DamagePlayer", player, 10)
How it Works:
- NetRay automatically batches small, frequent events.
- Batches are processed at a set interval (default 0.2 seconds).
- Compression is applied if the batch exceeds a threshold.
Security Features
Server-Side Validation
Preventing Exploits by Verifying Data:
NetRay:RegisterSecurityHandler("GiveGold", function(player, amount)
return amount >= 0 and amount <= 1000
end)
Circuit Breaker Protection
NetRay automatically disables problematic events if they repeatedly fail.
if NetRay:_isCircuitOpen("PlayerJumped") then
warn("Skipping event due to circuit breaker")
else
NetRay:FireServer("PlayerJumped", 10)
end
Conclusion
NetRay provides a more efficient, secure, and scalable way to handle networking in Roblox games. It is ideal for reducing lag, securing communications, and optimizing data transfer.
NOTE
This is my first module, and I expect mistakes, errors, and issues. I would appreciate any feedback and improvements.
Original Idea: @ffrostfall
BridgeNet2
If you find any issues, please let me know!
Version List
Current Version: v2.0.2
NetRay v2.0.2
- Fixed Multiple issues
- Binary encoding enabled
- improved module layout
- Not backwards compatible
NetRay v2.0.1
- Improved Binary Encoder/Decoder
Implemented Binary Encoder/Decoder during compression to save more bandwidth
NetRay v2.0.0
- Original Module