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

Make a number into a shortcut(?)

Asked by 4 years ago
Edited 4 years ago

I'm trying to make a script that changes a gui text to show "1m" instead of "1000000" as it's more neater and easier to read. I found a script that I could use but I'm not exactly 100% sure on how to use it on a gui text, here's the script in my gui:

1script.Parent.Text = game.Players.LocalPlayer.leaderstats.Cash.Value
2while true do
3    wait(0.1)
4    script.Parent.Text = game.Players.LocalPlayer.leaderstats.Cash.Value
5end

Here is the script I found but I tried using but couldn't get it to work:

01local suffixes = {"K", "M", "B", "T", "Q", "Qu", "S", "Se", "O", "N", "D"}
02 
03local function toSuffixString(n)
04    for i = #suffixes, 1, -1 do
05        local v = math.pow(10, i * 3)
06        if n >= v then
07            return ("%.0f"):format(n / v) .. suffixes[i]
08        end
09    end
10    return tostring(n)
11end
12 
13script.Parent.Text = toSuffixString(game.Players.LocalPlayer.leaderstats.Cash.Value)

If you know how fix this, please let me know.

0
The script you found is self explanatory, you just put the number in and it gives you the number with the suffix back. All you had to do was test it. SteamG00B 1633 — 4y
0
Also, make sure Cash is a string value CreationNation1 459 — 4y
0
How do I do that? stickymirro511 61 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

it is easy! Do it like:

01local StarterGui = __________ -- Show startergui here
02--Show like script.parent.parent.parent...(etc until it comes to the StarterGui)
03--As you should use a normal script, using game.Players.LocalPlayer won't work
04 
05local cash = StarterGui.Parent.leaderstats.cash
06 
07cash.Changed:Connect(function()
08    if cash.Value >= 1000 and cash.Value < 1000000 then
09        local shortened = tostring(cash.Value/1000)
10        script.Parent.Text = (string.sub(cash, 1, 2).."K")
11    elseif cash.Value >= 1000000 and cash.Value < 1000000000 then
12        local shortened = tostring(cash.Value/1000000)
13        script.Parent.Text = (string.sub(cash, 1, 2).."B")
14    elseif cash.Value >= 1000000000 and cash.Value < 1000000000000 then
15        local shortened = tostring(cash.Value/1000000000)
16        script.Parent.Text = (string.sub(cash, 1, 2).."T")
17        --keep continuing like that
18    end
19end

And also, make sure you use a Normal script to increase the currency and put this script too as a normal script. Both should be normal script to work.

0
Sadly didn't work, and just set the value to 0. stickymirro511 61 — 4y
Ad
Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
4 years ago

Just made a script that would do what you wanted, rather than changing your cash varable to a string vale i would leave that as a Number value and just hook up the function you found to the readout on your gui, Something like:

Gui Code: (Local Script)

01local function toSuffixString(n)
02    local suffixes = {"K", "M", "B", "T", "Q", "Qu", "S", "Se", "O", "N", "D"}
03 
04    for i = #suffixes, 1, -1 do
05        local v = math.pow(10, i * 3)
06        if n >= v then
07            return ("%.0f"):format(n / v) .. suffixes[i]
08        end
09    end
10    return tostring(n)
11end
12 
13--// this just changes your cash value so it shows the base 10 names in your suffixes table by powering it by 10 aka `10^0 = 1` , `10^1 = 10`, `10^2 = 100` etc....
14 
15spawn(function()
View all 26 lines...

And just incase the server script im using:

Code:

01local Players = game:GetService("Players")
02Players.PlayerAdded:connect(function(plr)
03 
04    local LS = Instance.new("NumberValue",plr)
05    LS.Name = "leaderstats"
06 
07 
08    local Cash = Instance.new("NumberValue",LS)
09    Cash.Name = "Cash"
10    Cash.Value = "0"
11end)

Hope this helps! :)

0
Thank you for trying to help, sadly your script just loops it and puts it on the wrong abbreviation. stickymirro511 61 — 4y

Answer this question