We use cookies on this site to enhance your user experience

Setting up a Leaderboard

Setting up a Leaderboard

  • General knowledge of Studio covered in Intro to Studio
  • Knowledge of scripting covered in Coding 2
  • Students should have completed Introducing the Adventure Game
  • Students should have a basic leaderboard
  • Lesson Time 10 - 15 minutes
    Optional Handouts
  • Adventure Game Reference
  • Learning Objectives
  • Understand how to display player variables like gold using a leaderboard
  • Learn how to use IntValues to store player variables
  • Now that you’ve created a leaderboard, it needs to show the player these numbers.

    • Gold - How much money the player has.
    • Items - How many items the player has collected from the world.
    • Spaces - The most items a player can hold at one time.

    Each one of these numbers will be an IntValue and follow the same series of steps when creating the Gold number.

    If you haven’t created a leaderboard yet, you can use the code in the box below.

    Track Player Items and Spaces

    1. Add a blank line after gold.Parent = leaderstats. This makes it easier to see where the code for different IntValues starts and stops.
    2. After the blank line, create a stat for Items by setting up a new IntValue the same way you did for gold.
    gold.Parent = leaderstats
    -- Create the Items stat
    local items= Instance.new("IntValue")
    items.Name = "Items"
    items.Value = 0
    items.Parent = leaderstats
    1. Create a new stat for the player’s bag spaces. Set spaces.Value to 2 so players start the game only being able to hold two items at once, encouraging them buy a new bag as soon as they can.
    items.Parent = leaderstats
    -- Create the Spaces stat
    local spaces = Instance.new("IntValue")
    spaces.Name = "Spaces"
    spaces.Value = 2
    spaces.Parent = leaderstats
    1. Test the game. Players should have a leaderboard showing Gold, Items, and Spaces.
    Leaderboard Not Working As Expected?
    • If you can’t see the number on the leaderboard, check that each IntValue is parented to leaderstats.
    • Make sure each IntValue is spelled exactly as shown
    • Check that the PlayerAdded event is at the bottom of the script

    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.