Get JobId from reserved server

So, I want to get a JobId from a reserved server, only thing is, I have no idea how lol.
I tried to do some research but was unable to find any useful information.
I dont have any code yet, as I thought I’d ask before hand, so uh yeah.

1 Like

I think it is not possible, since the reserved server does not yet exist? idk, if you try to connect 2 servers you can use MessagingService and, when the reserved server has a player, send a message to the origin server.

1 Like

So I looked at the docs, I cant figure out how I can send it to a specific server, Im just confused as I’ve never used MessagingService before, so any advice is appreciated

Anyway to get a reserved server code from a server? That would work too

as i know connecting only 2 servers with each other is impossible you can go around it by setting a certain code that only these 2 server knows “may be use datastore to save the code and then get it from the other server idk” and then check for the code if it is equal or not

Can I ask the purpose for this? What you could do is store the reserved server access code returned from TeleportService:ReserveServer() to a memory store if you need to access it across servers.

1 Like

Now may I ask, what is a memory store? Is that a roblox thing or a resource of some sort? It sounds familiar but idk

Oh and the point is I have a game, of which has CO-OP games, and I want people to be able to join their CO-OP worlds whenever they want, anytime someone tries to do it, and there isnt a server already, it then creates a new one (with ReserveServer())

1 Like

A little code, no idea if it works but it’s to give you an idea

Origin server
local Teleport = game:GetService("TeleportService")
local Messaging = game:GetService("MessagingService")

--		Server detection		--
local ServerFunctionList = {}
Messaging:SubscribeAsync("ServerConnect", function(message)
	local F = ServerFunctionList[message.Data]
	if not F then		return		end
	
	--		Call function		--
	local Success, Error = pcall(F)
	if Success then
		print("Server connected")
	else
		warn("Server not connected:", Error)
	end
	ServerFunctionList[message.Data] = nil
end)

--		Teleport		--
local function TeleportFunction(Players: {Player})
	--		Teleport success?		--
	local Success, Code = pcall(function()
		local ReserveCode, PrivateServer = Teleport:ReserveServer(game.PlaceId)
		Teleport:TeleportToPrivateServer(game.PlaceId, ReserveCode, Players)
		return ReserveCode
	end)
	if Success then
		ServerFunctionList[Code] = function()
			print("hey, im alive!", Code)
		end
	
		--		Clear data		--
		task.delay(30, function()
			ServerFunctionList[Code] = nil
		end)
	else
		print("Connection fail :(")
	end
end
--TeleportFunction(Players)     -->  Use me :D
Private server
local Messaging = game:GetService("MessagingService")
Messaging:PublishAsync("ServerConnect", game.PrivateServerId)

Yea, a pcall is missing for the MessagingService functions.

Connect a server-identifying messaging service topic to the server reserving the other server before teleporting the players, then when the reserved server becomes active make it send a message to that topic containing its job id. For example a topic you can use is Server-{jobId} where jobId is the job id of the initial server that reserves the other server. Then the reserved server sends its job id to that topic(assuming the reserved server knows the original server job id) and the original server picks it up.

If the reserved server doesn’t have a server-side way to know the server that created it, you can use a “trust most clients” method. Basically create client-sided teleport data for each user with the original job id, and when they get teleported, assume the original job id to be the one that appears the most within their teleport data(so it’s only exploitable if more people are exploiters and it’s a targeted attack).

This would work, but if players in other servers did this same thing, wouldnt the ServerConnect topic be triggered in like all servers? Thats my current problem with all of this

If you include a server unique identifier in the topic(as mentioned above) this should not be an issue.

Not really, I mean, if only one server handles this, there are no problems since they would not be connected to this “channel”.

If the private server is a copy of the original server, you could check if it is a private server so as not to use SubscribeAsync, If it is a reserved server (basically a private server without a host) you could check PrivateServerOwnerId and PrivateServerId.

The problem is getting said Unique identifier, as I have no idea how to make one

Does the reserved server know anything about the server that created it? If not set the teleport data of players to a unique identifier and do what I said above(trust the most players).

Edit: you can use PrivateServerId as a unique identifier which is returned from the ReserveServer function and is also accessible on the reserved server itself through game.PrivateServerId. Basically you need to reserve the server, establish the messaging service topic through the private server id it returns, then teleport the players to it. Then when the players go there and the server starts, use game.PrivateServerId as the messaging service topic to send a message back to the original server containing the game.JobId of the new one.

Ohhh well that would work well wouldnt it,
So it returns this?

local ReservedServerCode, PrivateServerId = TeleportService:ReserveServer(X)
1 Like

Use messaging service and set the topic to the servers private server id.

1 Like