# Number Abbreviation Help

You can write your topic however you want, but you need to answer these questions:

1. What do you want to achieve?
Hello, Im coop and im trying to make a GUI that displays one of my leaderstats, i successfully did that, but im trying to make the numbers Abbreviated.

For example,

Not Abbreviated: 2,489,902
Abbreviated: 2.48M

1. What is the issue?
Ive successfully did that, but it shows as a random number through math.random…
at first i did that as a test for the number abbreviation, but now i need to convert it into the players leaderstat.

2. Heres My Current Code
Local Script:

``````local AbbreviateNumber = require(game.ReplicatedStorage.AbbreviateNumber)

local Number = math.random(10000, 10000000)

print(Number)
script.Parent.Text = Number

local Text = AbbreviateNumber:Abbreviate(Number)

print(Text)
script.Parent.Text = Text
``````

Module Script:

``````local AbbreviateNumber = {}

local Abbreviations = {
K = 4,
M = 7,
B = 10,
T = 13
}

function AbbreviateNumber:Abbreviate(Number)
local Text = tostring(math.floor(Number))

local chosenAbbreviation
for Abbreviation, digits in pairs(Abbreviations) do
if #Text >= digits and #Text < (digits + 3) then
chosenAbbreviation = Abbreviation
break
end
end

if chosenAbbreviation then
local digits = Abbreviations[chosenAbbreviation]

local Rounded = math.floor(Number / 10 ^ (digits - 2)) * 10 ^ (digits - 2)

Text = string.format("%.2f", Rounded / 10 ^ (digits - 1)) .. chosenAbbreviation
else
Text = Number
end

return Text
end

return AbbreviateNumber
``````
1. What solutions have I tried so far?
Well 1 thing ive tried is changing
``````local Number = math.random(10000, 10000000)
``````

to

``````local Number = game.Players.LocalPlayer.PlayerData.Bux.Value
``````

and that sorta worked, but when i got more bux it didnt change on the text. which thats what i need it to do, i need it to update as soon as you get more bux.

is anyone able to help?

1 Like

Yep, Simply Get the leaderstats and the value, to change the text when the value is changed simply use a .Changed event, such as

"123.Value.Changed:Connect(function(property)
simply check if the property is the value if so then re run your function and set the players cash.
end)

3 Likes