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
game.Players.PlayerAdded:Connect(function(player) local leaderstats = Instance.new("Folder",player) leaderstats.Name = "leaderstats" local cash = Instance.new("StringValue",leaderstats) cash.Name = "Cash" cash.Value = 0 while wait() do if cash.Value >= 1000 then cash.Value = string.sub(tostring(cash.Value),1,1).."K" end end 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:
if tonumber(cash.Value) >= 1000 then cash.Value = string.sub(cash.Value), 1, 1) .. "K" end
Also you said cash.Value
= 0, you should change that to cash.Value = "0"
.
Hope this helps :)