How to make server system?

I want to teleport player to a server with specific minigame when he/she clicks the button. If the server doesn’t exists or full then the program should create a new private server. How can I do this? I couldn’t find any tutorials.

1 Like

You can use TeleportService

Yes, I know. But how to teleport player to a specific server which has specific minigames?

You will create server has a specific minigame and you can create if statement like:

playerclickedonbutton:connect(function()

if "PlayerClickedOnThisButton" then
teleport to circus minigame
end
 end)

But how to find server(s) of secific minigame?

You will create and every game has a different ids you can assign id on there

But what if the server is full?

First, you need to reserve the server to send players to.

To do this, you’ll need the placeId of the place to start. To find it, open the Asset Manager from the View tab. Go to Places and find the correct place (If there is only one place, then you’ll need to move your place into the same experience). Then click on the three dots and copy place id.

Once you reserve the server, you should get a game server id.

Then, to teleport the players, you’ll need to use TeleportService | Documentation - Roblox Creator Hub

But I want to have one experience for many different minigames.

Yes. That is what I mean.

Start Place - Lobby
Other places - Different places for each minigame. OR one place to host minigame for each server.

All on the same experience.

If you already have each place under places in asset manager, then you’re good.

I have no solution to this, but maybe I can tell everyone else what your talking about, with a better slate of words.


He wants to be able to teleport the player that clicked the button, to a specific server with the mini game that they selected. If the game finds a server that isn’t full, then the game will send that player to that server. If the game finds a server that is full, then it will create a new game, for that specific mini game. Same for if a server doesn’t exist.


This is what he’s trying to explain, but you all keep getting it wrong. I hope this helps for you all to understand.

1 Like

But if I have
Parkour minigame - server code X
Freeze tag minigame - server code Y
How do I store theese codes?

Yes, thank you this is what I mean. I am not a native English speaker so it’s very hard to explain my mind.

1 Like

@GulgPlayer.

Ah now I see (thank you @CRASHER_ZD111)

I am not sure on how to implement this either, as I have not ever done this before. However, maybe the Cross-Server Messaging | Roblox Creator Documentation would be of interest.

You could send a message to request for servers that are not full (Of a specific minigame you are looking for), and have each vacant server return their ids. Then, just pick whichever one you want and send the player.

If no server returns that they are vacant, you can use ReserveServer to generate a new one.

2 Likes

For a non English speaker, you did really well. I had a feeling that this was the reason that people didn’t really understand your need, but there’s no shame in that.

2 Likes

I have no idea if this helps, but I guess you could think of this as a Matchmaking System, since it has some similarity’s .

1 Like

Is this code good?

local MemoryStoreService = game:GetService("MemoryStoreService")
local TeleportService = game:GetService("TeleportService")

local activeMinigames = MemoryStoreService:GetSortedMap("ActiveMinigames")

local MINIGAME_PLACE_ID = 12529586079

local MinigameManager = {}

function MinigameManager.createServer(minigame: string)
	local accessCode = TeleportService:ReserveServer(MINIGAME_PLACE_ID);
	activeMinigames:UpdateAsync(
		minigame, function(servers)
			servers = servers or {}
			table.insert(servers, {
				accessCode = accessCode,
				maxPlayers = 10, -- Diffirent minigames allow diffirent amout of players
				players = 0
			})
			return servers
		end
	)
	return accessCode
end

function MinigameManager.teleportToMinigameServer(minigame: string, players: { Player })
	local servers = activeMinigames:GetAsync(minigame)
	local accessCode
	for server in servers do
		if server.maxPlayers - server.players >= #players then
			accessCode = server.accessCode
		end
	end
	TeleportService:TeleportToPrivateServer(
		MINIGAME_PLACE_ID,
		accessCode or MinigameManager.createServer(minigame),
		players
	)
end

return MinigameManager
1 Like

Yes! Absolutely.

Although the correct place to ask for code reviews is Help and Feedback > Code Review I can tell you that this code is well formatted and well done.

There is one problem though:

This can be nil. Instead, use:

local servers = activeMinigames:GetAsync(minigame) or {}
1 Like

There is also an issue in for loop:

for server in servers do

is wrong, it should be

for _, server in servers do
1 Like

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