Leaderstats Tutorial For Noobs

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)
14 Likes

:stop_sign: READ THIS BEFORE CREATING THE SCRIPT :stop_sign:
The following values on the player do not save. The values only add on but when you leave the game they will be set back to 0. I will be coming out with a datastore tutorial soon though. Thank you for using my script and I hope you enjoyed using it!

4 Likes

1 Like

Nice tutorial! Maybe you should just build onto this tutorial instead of creating another post when you’re ready to introduce saving data.

And if you are, I’d recommend showing them how to use UpdateAsync over SetAsync

Thank you for the response. I probably will do this but I need to learn more Knowledge on DataStores for leaderstats. Most of my leaderstats scripts I have tried don’t work for me but I will try to find more!

1 Like

Sorry for the late response, here’s a pretty good tutorial but I’m not sure if it’s very beginner friendly (since I’m not looking at it from that standpoint): DataStores - Beginners to Advanced

Thank you very much! I will be sure to check that out when I get a chance.

1 Like

Thanks for making this. Just a slight type in both codes. You had one too many “ends)”.

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	

	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 
	leaderstats.Parent = player
end)

Just wondering. Is the way we do leaderstats or other scripts going to change when roblox makes deferred events the new norm? I just read about them and am curious?

I’m so sorry! I really did not mean to do that.

Sorry but I don’t understand your question.

Apparenly not all code will work the same after the update because of the order of events processed.

I guess my question is, will this affect something as simple as leaferstats. Will we have to write the code different.

Maybe im just confused about the update and i hope my question applys to this.

Hopefully it shouldn’t as long as there not changing the coding language :joy: