Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Leaderboard showing 1000 when it should show 1k?

Asked by
tjtorin 172
6 years ago
Edited 6 years ago

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)
0
Your comparing a string value when you did local cash = Instance.new() try turning the value of cash to a number MahadTheIronSword 98 — 6y
0
Why not use `IntValue` instead? TheeDeathCaster 2368 — 6y
0
He can't use letters with a value that expects an integer. User#19524 175 — 6y

1 answer

Log in to vote
3
Answered by
chomboghai 2044 Moderation Voter Community Moderator
6 years ago

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 :)

Ad

Answer this question