Setting up a singular reserved server

So, I have a game I’m creating with an interesting teleportation/lobby system.

When you join the initial game, it’s just a lobby screen with some “Join Server” buttons. When you click that button, it teleports you to a place (in the same experience).

However, each one of these places will be a persistent world, meaning it will have a datastore and save buildings and things players do. So, there can realistically only be one server per place in this game.

Is it possible to set up a singular, permanent reserved server? I don’t know if a private server would work, because I’d have to enable private servers and I don’t want players to make their own private server on the main place/game. I know reserved servers are a thing, but I don’t know whether or not they’d work for this purpose.

My main concern with reserve servers is that the lobby place has a maximum server size of 1, so I don’t know if it would be possible to persist the join code across multiple lobby servers or whether it’s possible to access that reserve server code later somehow.

I hope this makes sense, please let me know if you have any questions!

3 Likes

If I am understanding it correctly. You want to make A server that has Other servers with saved Builds?

Option 1 → When you join your in a lobby with a List of different servers → Each Server leads to its own world Where players can Build… This is always saved and the same as it was left off.

or is it

Option 2 → When you join your in a lobby with One server → This acts like a global server for all players to build on. This is always saved and the same as it was left off for all Servers.

For starters, I would have the Starting place in 2 different places, one for building, one for the lobby. That way you can have more mex players for building.

Regardless what your trying to do is impossible by default. But by using Datastores/Memory stores is totally possible.

Now if you were doing Option one you would want to do something like to order each server:

local ExampleAllServers = { --Example of what you would save in a datastore
["Random Reserve Server Code"] = nil, --You would replace nil with all the infromation about the builds. 

["Another Random Reserve Server Code"] = nil --You would replace nil with all the infromation about the builds in that Server. 
}

Option 2, would completely skip this step as you would just do:

local ExampleOneServers = {nil} --You would replace nil with all the infromation about the builds in that Server. 

How would save this data though? Because I can’t save Instances?

Look into the Idea of Serialization & deserialize in datastores. Basically Breaking up Instances into Savable Values, and then building them back together when joining. This would then allow you, even in different servers, rebuild the creations other people made.


Hope this helps! Lmk if you have questions!

1 Like

I think MemoryStoreService could help you with that part

So, to clarify, within the experience there’s multiple places. There’s the main lobby, which you initially join, and then from there you can be teleported to other places within that experience.

Each place (aside from the lobby) should only have a single server at any given time. I suppose this would be your first option, so we’ll go from there.

Regarding the datastore method you suggested, do datastores persist across multiple places within the same experience? And would I be able to check for whether or not that reserve server still exists via the server code somehow? Or do reserve servers persist even when no players are in them?

And if they do persist when no players are in them, then is the only way to create it via code, or would it be possible to make them in a different way?

1 Like

I’ve read that MemoryStoreService works between servers. Would it also work across places within an experience/universe? Maybe a combination of MemoryStoreService and datastores (like the other guy suggested) would work?

And would MemoryStoreService persist even after the games have shutdown / all of the servers have closed?

2 Likes

No I think MemoryStoreService is just to send messages back and forth to the server anything relating to saving your going to have to do through DataStoreService im afraid

1 Like

What I kinda am Suggesting is that if no one is in the server, you make the server with the same Reserve code. And you load that data in. When everyone leaves, you save the Server in the Current state for when someone wants to join in again and then load in its data & repeat.

2 Likes

It still is worth noting though for my use. I could use the MemoryStoreService to likely send information about the server (i.e. number of players or factions present or something) back to the main lobby, which would be useful. Thanks!

2 Likes

Ahhh I see. Can you custom set the reserve codes, or are they just automatically generated? That could definitely work.

If I can get this solution to work I’ll upload a code snippet because there’s a few similar posts on the devforum about it without too much of a straightforward answer.

1 Like

What exactly are you trying to make if you dont mind me asking, like the game wise

1 Like

As I understand it, You can teleport to Reserve Servers once you have a code forever even when there is no players. So What I would do is make some codes, and save it to the datastore for those each to have “their own worlds” / Versions. And/or have your custom system adaptive as needed so once you Randomly generate one, you figure out some way to save it for it to be used for your needs (if players can make their own worlds for example)

You can generate Codes with TeleportService:ReserveServer(PlaceID)

2 Likes

So, in short, I am making a lobby you initially join with a “world map”. It’s for a medieval world and community. You’ll be able to travel between places, but when you initially join the game you need to choose which region you spawn in. Each region is it’s own “place” within the experience, and each region is a persistent world-building environment. So, players could build castles, or villages, or roads in each place that would persist over time and be a growing and interactive world. It would allow for a dynamic, changing world for several factions to interact with.

The main issue I’m facing, of course, is the server issue and limiting it to a single server per place so that it doesn’t overwrite datastores. I’m going to try out the method @OfficialPogCat is suggesting, and if it works I’ll post a little code snippet for those who may view this thread in the future who need a similar use-case.

3 Likes

Thanks @OfficialPogCat - your solution worked.

I’m attaching a bit of code I used below. It should work for anyone else who comes across this - I figured I’d share considering I haven’t seen any threads on the DevForum with completed solutions regarding this idea. The code below belongs in a server script. I have it set up so it’s activated via the client pressing a button, but you can probably modify this to your needs.

It will check the Datastore for a reserve server code already logged, otherwise it creates one and then teleports the player.

local TeleportService = game:GetService("TeleportService")
local DatastoreService = game:GetService("DataStoreService")
local RealmDatastore = DatastoreService:GetDataStore("YOURDATASTOREHERE")

local TeleportPlayer = -- Put the location of your RemoteEvent that activates this.

TeleportPlayer.OnServerEvent:Connect(function(Player, RealmID)
	print("SERVER: Grabbing Realm Data...")
	local getSuccess, realmCode = pcall(function()
		return RealmDatastore:GetAsync(RealmID)
	end)
	print(getSuccess, realmCode)
	
	if realmCode ~= nil then
		
		print("SERVER: We found the data: " .. realmCode)
		print("SERVER: Teleporting Player...")
		TeleportService:TeleportToPrivateServer(RealmID, realmCode, {Player})
		
	else
		
		print("SERVER: We didn't find the data, time to make it!")
		local code = TeleportService:ReserveServer(RealmID)
		print(code)
		local setSuccess, err = pcall(function()
			RealmDatastore:SetAsync(RealmID, code)
		end)
		if not setSuccess then
			warn("SERVER: Failed to save data: " .. err )
		end
		print("SERVER: Teleporting Player...")
		TeleportService:TeleportToPrivateServer(RealmID, code, {Player})
		
	end
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.