So, I made a script that gives money to a user every 1 minute. This money is shown on the player’s leaderboard, but I wanted it to be shown in a TextLabel. I have already tried several alternatives and have not been able to solve this problem.
CurrencyRiser
amount = 20 -- This variable is the amount of cash we will give each time.
timedelay = 60 -- This variable is the amount of seconds inbetween each time the cash is rewarded
currencyname = "Cash" -- This is the name of our Currency
while true do
wait(timedelay)
for i,v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("leaderstats") and v then
v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount
end
end
end
LeaderboardCash
game.Players.PlayerAdded:connect(function(plr)
local stats = Instance.new("BoolValue",plr)
stats.Name = "leaderstats"
local cash = Instance.new("IntValue",stats)
cash.Name = "Cash"
cash.Value = 0
end)
One option would be to connect a function to the .Changed event of the Cash IntValue object.
local textLabel = -- path to TextLabel
local cashObject = -- path to players cash object inside of leaderstats
cashObject.Changed:Connect(function(newValue)
textLabel.Text = newValue
end)
This is cause you only call this once, you will want to be able to tell when the value changes for the cash value and then display it on the text, to tell when it changes use this.
cash:GetPropertyChangedSignal("Value"):Connect(function()
-- your code here
end)
Not sure, not in the Studio
You will need a reference to the cash.
local cash = WhereEverThisIs
cash.Value +=20 – when they enter the game
Not we convert that to a string for the TextLable in the menu.
local TextLabel = game.StarterGui.ScreenGui.Frame.money.MoneyLabel
TextLabel.Text = tostring(cash.Value)
Also this: local stats = Instance.new(“BoolValue”,plr)
looks a bit sus … bool is true or false. Not sure what you’re doing here.
I placed the code inside a LocalScript inside the TextLabel, but as far as I know, the “leaderboard” is not an instance detectable by “script.Parent…”. Can you clarify this? I’m sorry if I’m wrong.
Absolutely, so when a player joins a game; their given a container of folders inside of their player. Here’s what it looks like;
Inside of here is where the players GUIs appear, same with your leaderboard stats. So, to make it so you can change the value correctly; you have to change the text of the textlabel to what the leaderboard stat says in your Players Leaderstats Cash value.