X Bridge v4 - Easy Client to Server communication

X Bridge is a fairly simple system that I find myself using a lot.

It allows you to funnel client-server communication through a single RemoteFunction.

Pros

  • Code is more legible
  • Faster developing

Cons

  • X Bridge does not support RemoteEvents
    If you want to squeeze out that extra performance, you can always manually make RemoteEvents. If this module gets popular, I might add something for this in the future

So how does it work?

I’m glad you asked.

X Bridge consists of two modules.
One module for the server side and one module for the client side.

The server side module returns a function formatted like this
ServerSide(array table_of_functions)

The functions inside the array should be formatted like this
table_of_functions.name_of_function = function(player caller_player, variable1, variable2, variable3, etc.)

The client side module returns a function formatted like this
ClientAccess(string name_of_function, variable1, variable2, variable3, etc.)

Usage

In a server script, you can do something like this:

-- Server Script
GiveClientAccess = require(game.ServerStorage.ServerSide)

insecureFunctions = {
	test = function(Player,Brick_Color)
		
		Brick_Color = Brick_Color or BrickColor.Black()
		
		print(Player.Name..' wants to spam '..tostring(Brick_Color)..' parts!')
		
		spawn(function()
			while wait(.25) do
				Instance.new('Part',workspace).BrickColor = Brick_Color
			end
		end)
		
		return true
	
	end,

	something = function(Player,Brick_Color)
		
		print('I do something too!')
		
		return 'pineapples'
	
	end
}

GiveClientAccess(insecureFunctions)

Once you have done that, you can call this function through the client side by doing something like this:

-- LocalScript
RequestServerFunction = require(game.ReplicatedStorage.ClientAccess)

firstRequest = RequestServerFunction('test')

print('First request returned',firstRequest)

secondRequest = RequestServerFunction('test',BrickColor.Red())

print('Second request returned',secondRequest)

anotherRequest = RequestServerFunction('something')

print('I would like '..anotherRequest)

Writing code this way makes it very intelligible.
Gone are the days of messing around with RemoteFunctions!

Feel free to reply with any critiques or suggestions.

2 Likes

Interesting!
I like the simplicity of this system, maybe I may even use this!

1 critique though, it’d be nice if there were functions for Server -> Client communication.

2 Likes