How to make leaderstats and get use to it: For beginners
Firstly, you usually want to load leaderstats in by using an event. Heres the event:
game.Players.PlayerAdded:Connect(function(plr)
what will this do?
- Will wait until the player is joined
- Will grab the local player
- Will make a variable inside of its function (plr) > which is the local player
Now you have to make stats. If you dont know what were gonna do here, we are going to make a folder, which all of the values like cash and stuff will be stored. It will also be in the player which will help access it and view leaderstats.
So here is the line for that.
local stats = Instance.new("Folder") -- Will create a new Folder
stats.Name = "leaderstats" -- Will name that folder
stats.Parent = plr -- Will place that folder inside of player
There. now when you join a folder will load inside of the player. Why? Because we used the event at the beggining.
Now, we will start off with are values. This is very easy.
local Name = Instance.new("StringValue") -- Will make a StringValue (Contains words instead of numbers)
Name.Name = "Team" -- Will name the StringValue
Name.Value = "Neutral" -- Will get a value of the StringValue
Name.Parent = stats -- Will place the value into the folder we made earlier.
Now thats only if you want the leaderstats to be in words because Stringvalues contain
words, Not numbers.
Now if you wanted a number, All you have to do is change StringValue with IntValue.
Heres what the script looks like:
String Value Script:
game.Players.PlayerAdded:Connect(function(plr)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = plr
local Team = Instance.new("StringValue")
Team.Name = "Team"
Team.Value = "Neutral"
Team.Parent = stats
end)
Int Value Script:
game.Players.PlayerAdded:Connect(function(plr)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
stats.Parent = plr
local Team = Instance.new("IntValue")
Team.Name = "Team"
Team.Value = 0
Team.Parent = stats
end)
I hope that helped!
By @Sea_KidTwelve, Recognized as AJ