How To Create A Round-Based Team Game

How It Works:

When the game starts, players will be put into a intermission and spawned at a lobby spawn point. Then, after the intermission is over, players will be divided into two teams and spawned at their respective spawn points.

NOTE: This is only how to make the framework of a game, you can use it to create anything, FPS Shooter, fighting game, etc etc. You will have to add things like gui and leaderstats yourself (unless this gets a lotta views then maybe ill make a part two).

Step 1: Set up

First off, create three spawn points, one for the lobby and two for the teams. Make sure the spawns have neutral and AllowTeamChange set to false and assign them all a team color. Name them appropriately.

Next, create the two teams with the same colors as the spawn points. Turn AutoAssignable to false.

Lastly, create a Script in ServerScriptService named “GameScript” with a Module Script inside it and another module script inside that one. Name the first “GameManager” and the second “Team Manager”.

Here's what your Explorer should look like

A

Step 2: The Game Loop

Open the Game Script you created and type out:

B

What this does is allow us to use the functions inside the module scripts we will make later.

Now, type out the loop:

C

The wait at the beginning is to allow the server to load before it begins the loop. The while true do loop is used to repeat what’s inside indefinitely. We will leave it blank for now.

Step 3: Game Manager

Firstly, open up the GameManager Module Script and change the prewritten code from “module” to “GameManager”. Next, we have to define the services and variables that will be used.

D

The variables can be changed after you’ve finished scripting the game but for now keep them as is for testing.

Now, we have to create the functions

E

How they work is pretty self explanatory. The StopIntermission function will return a true or false value based on whether or not there are enough players. The RoundEnded function will be left blank but its where you would put who the winners are.

Open back up your GameScript paste “GameManager:StartIntermission()” after the repeat and “GameManager:StopIntermission()” after the until. Then paste “GameManager:StartRound() GameManager:StopRound()” after that.

Step 4: Team Manager

Now open the TeamManager modules and change the prewritten code from “module” to “TeamManager” Then, define the services and variables.

F
(I made a mistake in the screenshot do not put the CharacterAutoLoads lol)

Now to create our function to assign the players team.

G

What we are doing is creating a table of the two teams and sorting them from smallest to largest, then assigning the player the smallest team. This will keep the teams even and the game fair. Then we are spawning the player in.

Next we make the function to un-assign the players team.

J

Make sure the BrickColor is the same color as your lobby spawn team color.
If you where to test now this wouldn’t work as we haven’t defined what Player is. To do this type out:

H

These functions go through each player and assign them to where they’re supposed to be. We will be using these functions in our GameManager.

Open the GameManager Module and paste “TeamManager:RemoveTeams()” into the StartIntermission function and “TeamManager:AssignTeams()” into the StartRound function. Be sure to put them above the wait function.

Then, at the bottom of the functions in the GameManager Script type:

I

This will assign the player to the correct spawning point if they join the game mid-round

Step 5: Testing

Now’s the time to playtest the game. Open the output to check for errors. Click the Test tab at the top of your screen then click Play under simulation, make sure your player is spawned at the lobby spawn and is neutral. Then after the specified time your characters team should change and be spawned at its team spawn.

If that doesn’t work go through this tutorial again and make sure there’s no typos, things in the wrong places etc. If it does work then Go to Clients and Servers under the Test tab and set it to 2 Player then hit Start. The same thing should happen except both players should be on their own team.

Congratulations you have created your own round based team game!!! If you have critiques or are still having trouble comment below!!! Thanks for reading!!! :happy1:

Source:

22 Likes