Player Stats

Player Stats

When players are in your game, they will want something to compete for. Developing something to compete for can take many forms. There could be tiers of upgrades, or cosmetic options they could buy or unlock. Instead, let’s create a leaderboard that can keep track of all player’s stats.

Setting Up the Leaderboard

The first step needed is to add a folder called leaderstats to players when they join. Naming the folder the leaderstats lets Studio know you want to create a leaderboard.

  1. Within ServerScriptService, open PlayerShipHandler.
  2. Create a new Folder when the player is added to the game that will store the leaderboard information.
  1. Under where you created the folder, create a new IntValue and parent it to the leaderstats folder created in the last step. The IntValue will store the number of enemies players have blasted.
  1. The IntValue’s name is what will be displayed to players. Change its name to Score and set its starting value to 0.

Now when players join the game, they’ll see a leaderboard on the right side showing that they haven’t earned any points yet.


Expanding onDestroyEnemy

In order to give players more points, the logic for onDestroyEnemy() in the BlasterHandler script written earlier needs additional code.

  1. Within ServerScriptService, open BlasterHandler and find the onDestroyEnemy() function.
  2. After destroying the enemy, get the player’s stats. This is done by finding the IntValue named Score, created earlier.
  1. Increase the value of enemyStat, which stores the player’s score, by one.

Now players will be able to compete to score the highest as the game plays on…

Expanding onDestroyEnemy() further

The logic written for hitting enemies is very short. There’s a lot you can add to make your game unique. There are visual effects like particles and explosions. Or, make combat more exciting by adding sound effects and camera shakes.

Many games feature an endless mode to the fun of the game. Using the tools learned in this series, expand the game to be endless.

(Hint: Use remote events to spawnEnemies() when enemies are hit by the player’s lasers)

  1. Within ServerScriptService, open EnemyHandler
  2. Make spawnEnemies use a parameter for the spawn count.
  1. Change the call to spawnEnemies() to use the constant variable.
  1. Create a constant variable.
  2. Create an enemySpawnEvent after the other variables are defined.
  1. After the other functions are defined, add a function called onEnemySpawnEvent()
  1. Call spawnEnemies with a value of one or more. Adding more than 1 enemy per enemy hit may quickly make your game feel unfair - so exercise caution.

Finished Project Example

With the player leader boards added, the core gameplay of the arcade action game is finished. You can download a final project example here if needed.

These documents are licensed by Roblox Corporation under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Roblox, Powering Imagination, and Robux are trademarks of Roblox Corporation, registered in the United States and other countries.

Previous Ship Blasters Next Earning Robux