Leaderstats and Adding a Value

How to make leaderstats and add a value.

by Bigmancozmo

Author Avatar

First, we will need a Script (Not LocalScript.) Put the script in ServerScriptService. Rename the script to "leaderstats" (all lowercase.) Now put the following code in the script:

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Parent = player
    leaderstats.Name = "leaderstats"
end)

Now, run it. In the Explorer and open the "Players." Inside of the Players open your player. You will see that there is a folder called "leaderstats." This name is special because it has to be spelled exactly like that to work. Now, continuing our script, we need to add a "Coins" value to this. We will be adding from our script we already have.

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Parent = player
    leaderstats.Name = "leaderstats"

    local coins = Instance.new("IntValue")
    coins.Parent = leaderstats
    coins.Name = "Coins"
end)

Now, if we run, we will see that above the player list, there is a value that says "Coins" Hope this quick tutorial helped!