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.
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!
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
2) Lets add a new button inside the ScreenGui we made
You can design it however you want
3) Lets make a new localscript inside the button
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.