Welcome to this Leaderstat tutorial for noobs. I will cover everything you need to know about leaderstats such as, how to parent the values, name the values, and how to add to the values you have in the players folder.
Copy Code For Lazy People:
game.Players.PlayerAdded:Connect(Function(player) -- The Script Will Activate When A Player Is Added
local leaderstats = instance.new("Folder") -- Creating A New Folder In The Player
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Cash = instance.new("NumberValue") -- Creating A New Value Inside Of Leaderstats (You can change cash to whatever you want.)
Cash.Name = "Cash"
Cash.Value = 0 -- (Starter Value)
Cash.Parent = leaderstats
-- If you want another value copy the script above and paste it here. Make sure to change the name
Put This In ServerScriptService.
Creating The Leaderstats Script :
Step 1
Making The Script.
First Step Is To Create A New Script.
Put The Script Into ServerScriptService.
Name The Script What Ever You Want But To Keep It Organized I Would Name It “Leaderstats”
Step 2
Activating The Script When A Player Is Added.
To Make The Script Work Whenever A Player Is Added Type :
game.Players.PlayerAdded:Connect(Function(player)
This Will Make The Script Work Whenever A Player Is Added To The Game
Step 3
Creating The Leaderstats Folder.
After Your PlayerAdded Function You Want To Create A Folder In The Player Which Is Where Our Player Variable In The Function (player) Comes in.
local leaderstats = instance.new("Folder") -- Creating A New Folder
leaderstats.Name = "leaderstats" -- Naming The Folder
leaderstats.Parent = player -- Parenting The Folder
Step 4
Creating The First Value.
After You’ve Created The Leaderstats Folder, You’ll Want Your First Value! If You Only Want 1 Value Skip Step 5. If You Want 2 You Can Do Step 5 Also
Put This Value Below The Folder Creation
local Cash = instance.new("NumberValue") -- Creating A New Value
Cash.Name = "Cash" -- Naming The Value
Cash.Parent = leaderstats -- Parenting The Value
Cash.Value = 0 -- Starter Value
Step 5
Creating The Second Value.
After You’ve Created The First Value, If You Want To Create A Second Value Do This.
Put This Value Below The First Value Creation
local Strength = instance.new("NumberValue") -- Creating A New Value
Strength.Name = "Strength" -- Naming The Value
Strength.Parent = leaderstats -- Parenting The Value
Strength.Value = 0 -- The Starter Value
Step 6 : Final
Final Product.
After You’ve Done All This, You Should Have A Script That Looks Something Like This
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats" -- The name must be leaderstats or else it will not work
leaderstats.Parent = player
local Cash = Instance.new("NumberValue") -- Make a new Number value (so it will be numbers only)
Cash.Name = "Cash" -- The name of the currency
Cash.Value = 0 -- Amount that the player will get once he joins
Cash.Parent = leaderstats -- Makes it inside the leaderstats
local Strength = Instance.new("NumberValue") -- Make a new Number value (so it will be numbers only)
Strength.Name = "Strength" -- The name of the currency
Strength.Value = 0 -- Amount that the player will get once he joins
Strength.Parent = leaderstats -- Makes it inside the leaderstats
end)