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

How to make a Value like 1000 to 1K into a text ?

Asked by 5 years ago
Edited 5 years ago

So I've been trying to make A Value like a cash from 1000 to 1K into a text button and I don't know how, now why I need it? To money display gui to make it shorter

Here my script :

while wait() do
game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.TextLabel.Text = "Cash:" .. game.Players.LocalPlayer.leaderstats.Cash.Value
end

2 answers

Log in to vote
2
Answered by 5 years ago
function sortText(num)
    local values = {{1000, "K+"}, {1000000, "M+"}, {1000000000, "B+"}}
    local str = ""
    if type(num) ~= "number" then num = tonumber(num) end
    for i = 1, #values do
        if num >= values[i][1] then
            str = (math.floor(num / values[i][1]))..values[i][2]
        end
    end
    return (num < 1000 and num or str)
end

This should do the trick. You can add more if you'd like, but I doubt you'd need to go above a billion.

Don't forget to accept the answer if it is what you were looking for!

0
But how I make it into the text? brodski40 8 — 5y
0
It already comes in text, you would just have to call the function. ObscureIllusion 352 — 5y
Ad
Log in to vote
-1
Answered by 5 years ago

I'm not entirely sure on that, I've tried before to see if there was a better algorithm myself, but this is the best I can think of for Simple

local placeTables = {1000, 10000, 100000, 1000000}
local placeLetter = {
    [placeTables[1, 3]] =  "k";
    [placeTables[4]] = m;
};
local player = game:GetService("Players")
local guiLabel = Player.LocalPlayer.PlayerGui.ScreenGui.Frame.TextLabel
local cashValue = Player.leaderstats.Cash.Value
while guiLabel do
    if cashValue = placeTables[1,4] then
        for_,Letter in ipairs(placeLetter) do
            if cashValue == Letter then
                guiLabel.Text = "Cash: "..cashValue..Letter
            end
        end
    end
end

There's a high probability this won't work;/

0
Did this not work? User#25448 0 — 5y
0
No. This code is completely invalid. User#6546 35 — 5y
0
"There's a high probability this won't work;/", Sorry, brains fried rn, at least i tried right, I knew what I was writing was bull;) User#25448 0 — 5y

Answer this question