Roblox Server Bridge

Roblox Server Bridge

Documentation and API Reference for Roblox Server Bridge ( RSB )

Github

If you have any questions or concerns → HeadBloxx#8939

Introduction

TL;DR: RSB allows developers to send cross-server requests, and receive a response from the other server(s).

RSB (Roblox Server Bridge) is a versatile and powerful module designed to seamlessly connect and exchange data between different Roblox servers. Acting as a robust bridge, RSB enables efficient communication and information retrieval across server boundaries, unlocking a whole new level of flexibility and functionality within your Roblox experiences.

With RSB, developers can effortlessly tap into the wealth of data scattered across various Roblox servers, streamlining access to critical information. Whether you need to retrieve player statistics, synchronize game progress, or facilitate cross-server interactions, RSB serves as the reliable conduit to bridge the gaps between servers.

This dynamic module empowers developers to create immersive and interconnected experiences by leveraging the power of multiple servers. By integrating RSB into your Roblox projects, you can harness the full potential of distributed server architecture, enabling seamless collaboration, data sharing, and real-time updates.

RSB simplifies the process of data retrieval and exchange, abstracting the complexities of server communication behind an intuitive and developer-friendly interface. It handles the intricate tasks of data synchronization, caching, and security, allowing you to focus on crafting engaging gameplay experiences without worrying about the underlying server infrastructure.

Whether you’re building massive multiplayer games, collaborative projects, or intricate interconnected worlds, RSB is the essential tool that empowers your Roblox creations to transcend the limitations of individual servers. Experience the power of seamless data transfer and unleash the true potential of your Roblox projects with RSB - the ultimate Roblox Server Bridge.

Before proceeding you should familiarize yourself with:


MessagingService
MemoryService

Installation

Download the RobloxServerBridge.rbxm or RobloxServerBridge.rbxl, or get it from the Marketplace and insert it in your game. You should preferrably place them inside ReplicatedStorage or ServerStorage
Note: Make sure to have Subscription.lua and Listener.lua parented to RobloxServerBridge.lua

Getting Started

Let’s write some code that will allow us to get the UserId of a player in another server by the player’s name.

  1. The first step is having the module installed, follow one of the aforementioned steps.
  2. Create a Script inside of ServerScriptService
  3. Require the module
local RSB = require ( PATH_TO )
  1. Create your Listener
  • The first parameter is the Identifier. An identifier is anything that can be used to identify the request you are listening for.
  • The second parameter determines whether or not the listener will be destroyed once it picks up the response.
  • The third parameter is the Callback. It’s the function that’s called when the listener picks up on a response, with a passed parameter containing the Payload of the message from the server to which the request was sent. To view the UserId of the player we’re interested in, we will print out the Result.
local RSB = require ( PATH_TO )

local Listener = RSB.NewListener ( "GetIDForHeadBloxx", true, function ( Payload )

    print ( Payload.Data.Result )
end)
  1. Create your Subscription
  • The first parameter is the Topic
  • The second parameter is the Process. A Process is a function that will be executed when the server receives a request, with a passed parameter containing the Payload of the request. It has to return a table consisting of Response, Identifier, and JobID,Responsebeing the response to the request, Identifier being the same Identifier which is inside the Payload, and JobID being the JobId of the server.
local RSB = require ( PATH_TO )

local Listener = RSB.NewListener ( "GetIDForHeadBloxx", true, function ( Payload )

    print ( Payload.Data.Result )
end)

local Subscription = RSB.NewSubscription ( "Test", function ( Payload )
	
	local Name: string = Payload.Data.Message
	
	return {
		Response = game.Players:FindFirstChild ( Name ).UserId,
		Identifier = Payload.Data.Identifier,
		JobID = game.JobId
	}
end)
  1. Add the Listener we’ve created to the Subscription
local RSB = require ( PATH_TO )

local Listener = RSB.NewListener ( "GetIDForHeadBloxx", true, function ( Payload )

    print ( Payload.Data.Result )
end)

local Subscription = RSB.NewSubscription ( "Test", function ( Payload )
	
	local Name: string = Payload.Data.Message
	
	return {
		Response = game.Players:FindFirstChild ( Name ).UserId,
		Identifier = Payload.Data.Identifier,
		JobID = game.JobId
	}
end)

Subscription:AddListener ( Listener )
  1. Send the request

We’ll be connecting the request sending line to a BindableEvent inside of ReplicatedStorage

local RSB = require ( PATH_TO )

local Listener = RSB.NewListener ( "GetIDForHeadBloxx", true, function ( Payload )

    print ( Payload.Data.Result )
end)

local Subscription = RSB.NewSubscription ( "Test", function ( Payload )
	
	local Name: string = Payload.Data.Message
	
	return {
		Response = game.Players:FindFirstChild ( Name ).UserId,
		Identifier = Payload.Data.Identifier,
		JobID = game.JobId
	}
end)

Subscription:AddListener ( Listener )

game.ReplicatedStorage.BindableEvent.Event:Connect ( function ()
  
  Subscription:SendRequest ( "HeadBloxx", "GetIDForHeadBloxx" )
end)

And there you go, you now have a script that will get HeadBloxx’s UserId whilst HeadBloxx is in another server.

Although Identifiers prove more valuable in complex scenarios, I’ve chosen this simple example to introduce the module.

API Reference

Listener Class

ListenerModule.New ( Identifier: any, DestroyedOnCallback: boolean, Callback: ( Payload ) -> nil ): Listener

This creates and returns a new Listener instance.

Listeners listen for request responses from servers.

Parameter Type Description Default
Identifier any The Identifier that identifies the response it’s listening for nil
DestroyedOnCallback boolean Determines whether or not the listener will be destroyed when it picks up a response nil
Callback function The function that will handle the result nil

Response body ( Result being the return value of the Process function. ) :

{
			
	Result           = Result.Response,
	Identifier       = Result.Identifier,
	JobId            = game.JobId,
	JobIDToRespondTo = Payload.Data.JobId -- JobId of the requesting server
			
}

Returns: Listener

Note: The Identifier is stringified using tostring.

Subscription Class

SubscriptionModule.New ( Topic: string, Process: ( Payload ) -> any ): Subscription

This creates and returns a new Subscription instance.

Parameter Type Description Default
Topic string The topic that will be used for MessagingService nil
Process function The function that will handle the response nil

Returns: Subscription

Note: This function creates two subscriptions to MessagingService

Subscription:SendRequest ( Message: any, Identifier: any )

This sends a request to all servers with it’s Topic.

Parameter Type Description Default
Message any The message that will be sent for with the request nil
Identifier any The Identifier used to identify this particular request nil

Request body:

{
	Identifier = Identifier,
	Message    = Message,
	JobId      = game.JobId
}

Returns: nil

Subscription:AddListener ( NewListener: Listener )

This adds a listener to the subscription.

Parameter Type Description Default
NewListener Listener The Listener to be appointed to the subscription nil

Returns: nil

Subscription:RemoveListener ( Identifier: string )

This adds a listener to the subscription.

Parameter Type Description Default
Identifer string The Identifier associated with the Listener to be removed nil

Returns: nil

Subscription:Unsubscribe ()

Deletes the Subscription instance, disconnecting from both subscriptions to MessagingService

Returns: nil

Configuration

The SameServerResponsesAllowed variable inside Subscription.lua determines whether or not one server can send a request or response to itself.

FAQ:

How do I test this?

The way I tested it was a bit unorthodox.

  1. You want to publish your game
  2. Make the maximum server size 1
  3. Use Multiple Roblox to run two instances of the roblox client
  4. Test your code!

How do I report a bug or request a new feature?

I’m the most active on discord → HeadBloxx#8939

18 Likes

Awesome! This is really handy rather than using some lopsided communication with data-stores. I’ll definitely be using this. Thank you.

3 Likes

Be aware, this module uses exclusively MessagingService, making it incredibly unreliable. At this very moment I’m working on a newer version that incorporates MemoryStores. Hang tight!

1 Like

bro how did you made this? This is very useful!
Great work!

2 Likes

Forgot to mention it’s fixed now

1 Like

What is the API rate limit?

Let’s say I wanted to create a Discord inside of my game where players can message each other from any server, how many messages could a user send before getting rate limited?

Because I remember trying out something similar with the MessagingService, and to say the least it was pretty limited.

Edit: I just tried it out and the API rate limit is the same as MessagingService(Kind of dumb of me) since it is the same service just in a module, what would be nice would be some sort of queue system so when you exceed the limit instead of your request getting thrown out it stores somewhere until it is able to be sent.

One way I would go about tackling that would be with a pcall function and if it detects an error then add the last request to a table, then have a loop that every 15 seconds tries to resend the first item in the table, of course there are many other ways to do it and do it more elegantly but for a quick fix that should be doable

2 Likes

You wouldn’t want to use my module for what you want to achieve. This module allows users to retrieve data from other servers, that’s its purpose. You only want to send data.

But I guess your concern is the limit. I’m currently a bit busy as I’m launching two games but I will contact you when (and if) I solve that issue. Although there is a one-way pooling system which I should make two-way, I thought it would solve it

Thanks for reaching out!

  • HeadBloxx
1 Like

Yeah, no problem I can actually just make a pull request and then you can review if you like what I add then just merge it.

I was going to do it either way, so I don’t mind just doing on yours.

1 Like

Yeah sure go ahead, send the pull request!

1 Like