How to make leaderstats in roblox studio | For beginners

How to make leaderstats in roblox studio | For beginners

1) Make a server script inside ServerScriptService | game.ServerScriptService
You can name the script however you want, it doesn’t matter.
image

2) We need to detect if the player joins
First of all, you need to detect if a player joins. We’ll do:

game.Players.PlayerAdded:Connect(function(player)
	
end)

Great, now we have successfully detected if a player joins.

3) Lets make a folder inside the player.

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder") -- Makes a new folder
	leaderstats.Name = "leaderstats" -- The name of the folder must be leaderstats oherwise it will not work
	leaderstats.Parent = player -- The parent of the new folder we made will be inside the player
end)

4) Make your currency.
We need now to make a currency now, lets make money for example.

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 money = Instance.new("IntValue") -- Make a new int value (so it will be numbers only)
	money.Name = "Money" -- The name of the currency
	money.Value = 50 -- Amount that the player will get once he joins
	money.Parent = leaderstats -- Makes it inside the leaderstats
end)

Full source

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

5) We are done!
We will now have the leaderstats we made!
image

Note:
The leaderstats will not be saved. I will may upload a tutorial for database in my next tutorials.

Now, lets make a button that gives us money!

1) Lets make a new ScreenGui inside StarterGui | game.StarterGui
image

2) Lets add a new button inside the ScreenGui we made
You can design it however you want
image

3) Lets make a new localscript inside the button
image

4) Finally, lets script it!

local leaderstats = game:GetService("Players").LocalPlayer:WaitForChild("leaderstats")
local Currency = leaderstats:FindFirstChild("YourCurrency") -- Change the "YourCurrency" with the currency you made! In our case is Money
local button = script.Parent -- Our button

button.MouseButton1Down:Connect(function() -- Detects if the player clicked the button
	Currency.Value = Currency.Value + 20 -- When the player will click the button, his money will go higher by 20.
end)

And we are done! Now you will have your amazing leaderstats.

35 Likes

LocalScripts cant change a server-side variable. You would have to use a remote event when the TextButton is clicked.

7 Likes

Adding to what @noblemaxx said you can also use a server script by getting the location of the UI and see if its clicked. Yes it would in theory work.

5 Likes

In my opinion you should also show begginers how to savte those stats with datastore

8 Likes

Yeah, I will do it on next tutorials. Datastore is a little more complicated, so I didnt showed it in that post.

5 Likes

You explained it pretty well. Good job!

2 Likes

Thank you so much for this tutorial that’s exactly what I needed! But I don’t know how to make it save…

Did you uploaded this tutorial? If yes, can you link it please?

3 Likes