I am making a minigame game, and obviously it has a winning system. I’m a bit stumped, however, on how I should approach this. Each minigame has different winning conditions (last player standing, last team standing, etc.).
How would you recommend I write a system for this?
For the last player standing, you’d need to store an array of players and remove them one-by-one if they’ve died, got eliminated, etc. The last player that remains in the array is the winner of that round.
Last team standing is a bit more complicated. You have to store multiple arrays depending on how many teams you have, and remove the player from the array corresponding to the team if they’ve died. If one or more players on a certain team remain after the rest of teams have died off, then they’re the winner of that round.
Since you have different winning conditions for each minigame, I would recommend making a bindable event for when the game ends. No matter what game mode it is or what the condition was for someone to win, it calls the same event that resets the game. You can also pass an array of players that won the minigame through the bindable event and it can distribute points to the players respectively.
I have a modulescript full of code to setup voting, spawn in players, etc. Then for each minigame I have a single script to run any minigame code(there’s not much).
A nice and tidy way to go about this is to create a module containing all of the minigame’s data, such as how the game performs and the duration of the round, etc. In each minigame module, you can create a value that represents different gamemodes such as Last Player Standing and Team Standing, etc. You can represent this in a variety of ways such as numbers or strings.
for timer = 300,0,-1 do
wait(1)
YOUR_VALUE.Value = timer
end
-- loop through all of them and check values
for _, Player in pairs(game.Players:GetPlayers()) do
if Player["YOUR_FOLDER_STORAGE_NAME"]["YOUR_VALUE_NAME"].Value == YOUR_CONDITION then
-- do some stuff here
end
end
this loops through every player after the timer and after this do some event stuff on the script