How do I make a TextLabel that shows the total amount of coins a player collects?
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:Wait()
local textLabel = script.Parent
local leaderstats = player:WaitForChild("leaderstats")
local Coins = leaderstats:WaitForChild("Coins")
while task.wait() do
textLabel.Text = Coins.Value
end
sorry, I’m not english. I meant the total amount they collected while playing the game. Not the amount they have. I plan on adding a reset button, but I want the coins to remain the same.
The amount they have collected is the same as the amount they have, no?
I mean, I might be adding rebirths to my game and I want the textlabel to show the total amount which stays the same even if they rebirth.
And if they collect 1 coin after rebirthing it will add + 1 coin to the amount they had before
It updates constantly, so whatever the coins value is, will show in the label.
Thats not what I meant. I mean the total amount they collected in the time they played the game not the amount right now
Still not sure what you mean? Are you trying to make it so that coins save when a user leaves and rejoins?
No. I don’t know how to expain this.
For example someone collects 2 coins, it will show 2 coins.
Then they reset their coins or something and they colect 1 more coin
Then I want the textlabel to show 3 coins instead of 1
Oh, I see well you’ll just need a second stat for that, like this:
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:Wait()
local textLabel = script.Parent
local leaderstats = player:WaitForChild("leaderstats")
local Coins = leaderstats:WaitForChild("Coins")
local TotalCoins = leaderstats:WaitForChild("TotalCoins")
while task.wait() do
textLabel.Text = TotalCoins.Value
end
So just add to “TotalCoins” the same way you do for “Coins” but when the user resets only reset the “Coins” stat not “TotalCoins”.
Oh okay, that was easy. I could’ve done that myself. Sorry for wasting your time.
No problem & yeah it is pretty simple.