In case my title was awfully phrased, I want to have a TextLabel that gets its value from Player.leaderstats.Cash and it works well except for that I want it to always have a "$" in front of the Cash.Value
1 | local player = game.Players.LocalPlayer |
2 | player.PlayerGui:WaitForChild( "Balance" ) |
3 | local cashText = player.PlayerGui.Balance.CashBal |
4 |
5 | player.leaderstats.Cash.Changed:connect( function () |
6 | cashText.Text = game.Players.LocalPlayer.leaderstats.Cash.Value |
7 | end ) |
here's the hierarchy just in case https://gyazo.com/09cffa0a3c50fc41682931e580dc51b8
If you want to go simple, you can just concatenate to the beginning/end.
1 | print ( "$" .. 1234 ) -- prints "$1234" |
However, the preferred way is to use string.format
1 | print ( string.format( "$%d" , 1234 )) -- also prints "$1234". |
2 | -- "%d" in the string pattern indicates that we want to replace it with a number. |
The advantage of the second method is that it is more extensible. If you want to print out extra decimal places for fun, you can change it up, like so:
1 | print ( string.format( "$%0.2f" , 1234 )) -- prints "$1234.00" |
2 | -- "%0.2f" indicates that we want to print a number with decimal digits, up to the second digit after the decimal point. |
More about Format Strings in Roblox Wiki.