Multi-match instance infrastructure planning

Hi! Up to this point, I have only created small test games that are usually round based where everyone is playing the same one game. For my game, I will need to have multiple instances of the same game going at the same time.

For example, recently I have created a lobby system that puts players into the same table and therefore the same lobby. When I press the ready button in that lobby, I want a separate instance of my game (a turn based RPG system) to start for only those few players and nobody else. Now if another lobby with players presses that same button with their own players, they should get their own instance of the gameplay as well. So on and so on.

I DO NOT WANT TO TELEPORT PLAYERS OUT OF THE GAME INTO ANOTHER SERVER. I want all of the gameplay mechanics and elements to be hosted inside of one server so the matches are as smooth as possible going in and out of gameplay.

If you require any further details or know a way to plan for what I’m describing, your contribution would be much appreciated!

2 Likes

Hi @Sclooshy,

I think this requires a module script that controls a game within the server. This module script will control the internal lobby, the game location, and all the other mechanics.

My approach would have a lobby module that has a group of players. When all players are ready, the lobby module teleports the players to the correct location and begins the game logic. This game logic would also have to be its own module so it can be copied to other lobby groups instead of being a static presence.

local LocalLobby = {
     CurrentPlayers = {},
}
LocalLobby.__index = LocalLobby

function LocalLobby.New(lobbyLocation: CFrame)
     LocalLobby["Location"] = lobbyLocation
end

function LocalLobby:AddPlayer(player:Player)
     table.insert(self.CurrentPlayers, player)
end

function LocalyLobby:CheckIfAllPlayersAreReady(): boolean
     for _, player in self.CurrentPlayers
          -- check if player is ready
          -- if any player not ready, return false
     end
     -- If made it here before returning false, all players
     -- all players are ready, return true
     return true
end

function LocalLobby:StartGame()
     -- Create copy of game module, insert players, teleport players, and start game?
end

function LocalLobby:EndGame()
     -- Maybe some clean up logic goes here?
end

return LocalLobby

EDIT: Forgot to return LocalLobby

2 Likes

Oooh that’s interesting. I was thinking of a similar idea with task.spawn() but I completely forgot that’s the exact thing module scripts are for!

So how it would work is something like:

  • When the ready button is pressed by the lobby owner, all of the data that I want to send to the new game instance gets sent to the game module script, where actions run for only THOSE specified players from the script require.

  • Since this is a module script, this can be ran for multiple players at multiple times as opposed to a server script where it can only have one instance (Unless you’re using task.spawn() or there is something I don’t quite understand about the difference between server and module scripts.)

  • This module script would be held in server storage instead of replicated storage as since it is hosting all of the game logic, we do not want exploiters to be able to access the module to cheat so easily.

  • When the game is done, clean up logic is ran on all of the players and then afterwards, their player gets reset back to the main menu.

To reply in order:

  • Right, so the LocalLobby would contain all the players you wish to send to the Game module script. When the lobby owner pressed the ready button, the game module script is only ran for those players. Includes the teleporting the players, starting the game, round control, etc. etc., and eventual clean up.
  • Correct. A module script can be reused. I am a fan of Luau OOP, as I showed in my previous comment, but there are many ways to go about it. Please read over this as there are some things about module scripts that may surprise you: Intro to module scripts | Documentation - Roblox Creator Hub
  • Correct. You want all you game logic on the server. Various events will control everything client side.
  • Correct. I would take special care of cleaning up server resources as to not bog down the entire server.
1 Like