Showing Cash in TextLabel

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)

I need it to show where the “$” are. (TextLabel)
Capturar1312

2 Likes

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)
1 Like

Where should this code go? Inside some script? Or in a new Local Script within the TextLabel?

1 Like

TextLabel.Text = tostring(cash.Value)

2 Likes

It showed the initial value (0), but after 1 minute, only the number on the leaderboard changed. Maybe it’s because of the leaderboard?

1 Like

Text is always a sting. So you have to convert it from an int.

1 Like

Sorry, I didn’t understand what you meant by that. Can you explain a little better?

1 Like

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)
1 Like

The input for the textlable is a string. It needs to be entered as a string.
20 is an int … “20” is a string.

1 Like

Is this correct?

local TextLabel = game.StarterGui.ScreenGui.Frame.money.MoneyLabel

cash:GetPropertyChangedSignal("Value"):Connect(function()
	game.Players.PlayerAdded:connect(function(plr)
		local stats = Instance.new("BoolValue",plr)
		stats.Name = "leaderstats"

		local cash = Instance.new("IntValue",stats)
		cash.Name = "Cash"
		TextLabel.Text = tostring(cash.Value)
	end)
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 found BoolValue a little strange too, but I don’t know how I can replace it…


Put this inside a local script in the Cash GUI, and make sure the LeaderStats variable actually finds leaderstats.

local LeaderStats = script.Parent.Parent.Parent.Parent.leaderstats
script.Parent.Text = LeaderStats.Cash.Value
LeaderStats.Cash:GetPropertyChangedSignal("Value"):Connect(function()
	script.Parent.Text = LeaderStats.Cash.Value
end)

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;
image

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.


Ah yes, now I see the value. Now, how can I make the script recognize this value?
Capturar23123132

By referencing it, as I did. I simply went from the GUI, and kept adding a .Parent to the line until I got to the Player, then went to leaderstats.

Is this correct?

local LeaderStats = script.Parent.Parent.Parent.Parent.Parent.Parent.Players.leaderstats
script.Parent.Text = LeaderStats.Cash.Value
LeaderStats.Cash:GetPropertyChangedSignal("Value"):Connect(function()
	script.Parent.Text = LeaderStats.Cash.Value
end)

Test it, and see if it works. If it works, then you did it correctly.

It didn’t work, but apparently it’s correct.