I want my leaderboard to show 1k instead of 1000 and also do that with higher numbers but it is not working correctly.
I am also getting an error saying: ServerScriptService.leaderboard:9: attempt to compare number with string 20:31:42.420 - Stack Begin
01 | game.Players.PlayerAdded:Connect( function (player) |
02 | local leaderstats = Instance.new( "Folder" ,player) |
03 | leaderstats.Name = "leaderstats" |
04 | local cash = Instance.new( "StringValue" ,leaderstats) |
05 | cash.Name = "Cash" |
06 | cash.Value = 0 |
07 |
08 | while wait() do |
09 | if cash.Value > = 1000 then |
10 | cash.Value = string.sub( tostring (cash.Value), 1 , 1 ).. "K" |
11 | end |
12 | end |
13 | end ) |
The problem is your cash
object is a StringValue
, and you are checking if the string is >= 1000
. You can't check if a string is larger than a number, that's like saying:
is 'd' greater than 6?
So you instead have to convert the string to a number, and then perform the comparison:
1 | if tonumber (cash.Value) > = 1000 then |
2 | cash.Value = string.sub(cash.Value), 1 , 1 ) .. "K" |
3 | end |
Also you said cash.Value
= 0, you should change that to cash.Value = "0"
.
Hope this helps :)