PrimaryServer, A gateway for all servers

Hey all!
I’m releasing something I’ve been toying with for the last few days based on an idea I had a long time ago.
https://www.roblox.com/library/5972092620/PrimaryServer
This is best called PrimaryServer because it’s just that: a primary server to act as the middleman for all servers.
Say you have settings on Trello that you run your game on, it wouldn’t make sense for 50 servers to make 50 requests when you can select 1 server to be the gateway.
This is something I failed to enact, but hopefully will re-make with, in my past release [Open Source] Fast-Flag System - #12 by LordMerc
Some pictures of the PrimaryServer in action:
https://media.discordapp.net/attachments/770711776139411476/778699347826311238/unknown.png
This is two different servers, the left side is the current host while the right side is another server.
Some examples can be found in the primaryserver script, but feel free to read the module itself if you can bear in mind the pain of the code. It’s not the best formatted, but it works.

local API = require(script.ServerSelector)
local Service = API:init()
Service:on('ready',function()
	print('API is now ready to be used!')
	print(Service:GetCurrentServer())
end)
Service:on('HostChanged',function(HostID)
	if HostID == game.JobId then
		print('This is now the current host server!')
	else
		print('Server',HostID,'is now the host server!')
	end
end)
local tab = {
	"LordMerc is cool man!"
}
Service:on("Trello",function(SentTab)
	print('Received update from the host server!')
	print(SentTab)
end)
while wait(3) do
	if Service:GetHostServer() == game.JobId then
		print('As host, you are the one sending data')
		Service:Trello(tab)
	end
end

Fair note, any function (example being the Service:Trello()), will not run on the host server as that can be done when you are sending the data out at the time same.

while wait(3) do
	if Service:GetHostServer() == game.JobId then
		print('As host, you are the one sending data')
		Service:Trello(tab)
       -- Now your server runs the code here or in a function outside
	end
end

So far after testing it many times I’ve yet to run into any problems, but it’s unavoidable to happen. If you have issues or questions feel free to ask!

14 Likes

Very nice, I will probably use something like this in the future <3

1 Like

Isn’t it kind of dangerous to rely on MessagingService for core gameplay features? From what I remember, MessagingService doesn’t actually throw an error if an error occurs while sending a message to another server.

2 Likes

Primarily it’s not exactly for core gameplay features that could ultimately break. Based on what purpose I intended for this, you could do the following:

local Settings = {
"UpdateTime" = 5,
"IsEnabled" = false
}
while wait(15) do
 local TrelloData = TrelloFunction()
 for i,v in next, Settings do
  --However you chose to do
  Settings[v] = v
 end
end

Note it’s a broad example that can be expanded on

1 Like

Looking kinda neat right there, might have use for something like that in the future. Who knows.

1 Like

The dev hub even says to not use MessagingService if its delivery is critical but you could use DataStore instead

2 Likes

There shouldn’t be nothing critical using this except to pair it with something similar to my LiveEvents. My intended purpose with this was simply management-ease for 1 server instead of several. Datastore isn’t necessarily a better option due to throttling.

1 Like