Minigame Scripts - Which option would be best?

Hello!
I am working on a minigame-like game for a while and now it’s time to code different minigames, but I have encountered with a question in my mind.

Now, there are two scripts that is handling games. One is the main script which handles the whole game, copying deleting moving games or doing other stuff when is required etc. and the other one has all the scripts that each minigame require to run. So, main script runs the other one, but in my game, main script needs to keep running while the minigame script runs too. So, I have two options in this case:

  1. Making a ModuleScript that has all the minigames’ scripts. In this case, main script calls the function in ModuleScript, but ModuleScript would run a spawn function, so Module could return and MainScript could continue it’s process while Minigame runs.

  2. Making a ServerScript which gets fired with a BindableEvent. In this case, Main script fires a bindable, and keeps going. Also Minigame script starts working too.

Which option would you suggest? Or could you suggest any other option? Thanks for reading!

Note: This is my first topic. I am sorry if I did anything wrong :frowning:

4 Likes
  1. One server “core” script, and a module script for each mini-game (w/ all the dependencies and whatnot handled within) ??

“Main” would look something like this

local Games = "path_to" --folder containing mini-game modules

local Players = game.Players;
local Player_Req = 5;

local function getRandomGame()
	local games = Games:GetChildren()
	return games[Random.new():NextInteger(1, #games)]
end

local function start()
  if #Players:GetPlayers() >= Player_Req then
	--//..
		
	local thisGame = require(getRandomGame())
		
	--//...
    start()
  end
  Players.PlayerAdded:wait()
  start()
end

and a mini-game (module)

local Game do
	Game = function()
		--//...check dependencies,
		--//...load maps(s)
		--//...position players
		--//...[etc]
	end
	return Game
end
4 Likes

Thanks for your answer!
I get it that it would be easier to edit every game but why would there be too many modules if only one can handle it all? Does it bring any performance or other advantages?

Do not confuse my answer as a recommendation. Either one is fine and neither should take a drastic toll on your game’s performance. I just personally prefer compartmentalizing my projects in ways that can easily be scaled for use in other projects.

1 Like

Oh, sorry :sweat:
Thanks for your suggestion :smile:

1 Like

I do something similar but I make each gametype an OOP styled Object with a main SuperClass that contains all of the information and methods that are expected to be used in most if not all game modes. Then each game mode is just as a subclass of the main module.

I find that this approach makes scaling the game with many different game modes is really easy and if there is ever a game mode where you want to do something radically different then simply overwrite the original methods from the super class.

5 Likes

Exactly.

I never considered the OOP approach though… sounds like it’d save some redundancy.

2 Likes

Not to bump but… Any other suggestions? If not I guess I’ll go with second option :neutral_face:

ImageLabel and VineyardVine’s suggestions seem to be very good options.

I would personally do it like VineyardVine suggested though.

not that option 2 is bad at all.

1 Like

Thanks everyone for their answers and suggestions, I thought about them but since I would not make a minigame-game in future except this one I’m making right now, I think second fits the best for my purpose.
Loves to y’all! <3

2 Likes