I'm trying to make a leaderboard by trying to get the IntValue in each player, but I don't know where to start.
If anyone has any advice, I'd surely appreciate it!
01 | local function onPlayerJoin(player) |
02 | local leaderstats = Instance.new( "Folder" ) |
03 | leaderstats.Name = "leaderstats" |
04 | leaderstats.Parent = player |
05 |
06 | local Coins = Instance.new( "IntValue" ) |
07 | Coins.Name = "Coins" |
08 | Coins.Value = 0 |
09 | Coins.Parent = leaderstats |
10 | end |
11 |
12 | game.Players.PlayerAdded:Connect(onPlayerJoin) |
I hope this helped answer your question. If you have any problems ask me.
(EDIT) I forgot to mention that you insert a script inside of serverscriptservice and paste that
another edit! since you wanted your code to coins as a screen gui just put this script inside of a text label
1 | local player = game.Players.LocalPlayer |
2 | local stats = player:WaitForChild( "leaderstats" ) |
3 | local coins = stats:WaitForChild( "Coins" ) |
4 | local text = script.Parent |
5 |
6 | text.Text = "Coins: " ..coins.Value |
7 | coins( "Value" ):Connect( function () |
8 | text.Text = "Coins: " ..coins.Value |
9 | end ) |
if you have any more questions ask me!
Well I can explain throughly so you can understand...
Let’s start with the function()
that will run when the player
joins the game
1 | game.Players.PlayerAdded:Connect( function (player) |
2 |
3 | end ) |
Now let’s reference the Leaderstats
, it should look like this
(it is a “Folder” by the way)
1 | game.Players.PlayerAdded:Connect( function (player) |
2 | local leaderstats = Instance.new( "Folder" ) |
3 | leaderstats.Name = "leaderstats" |
4 | leaderstats.Parent = player |
5 | end ) |
There. , NOW let’s make some money!
Won’t be hard don’t worry!
Cash will not be a Folder
but it’s a IntValue
01 | game.Players.PlayerAdded:Connect( function (player) |
02 | local leaderstats = Instance.new( "Folder" ) |
03 | leaderstats.Name = "leaderstats" |
04 | leaderstats.Parent = player |
05 |
06 | local Cash = Instance.new( "IntValue" ) |
07 | Cash.Name = "Cash" |
08 | Cash.Value = 0 |
09 | Cash.Parent = "leaderstats" |
10 | end ) |
Also if you want to change the amount of Cash you have then, change the number of the Value
And now you are finally done! If you need any further help please contact me here. Bye!