So I wrote a Module script to abbreviate numbers in my game server, through Replicated Storage. Then I used the Module Script in a Local Script through a starter Gui, that will appear to the player showing them the amount of currency they have through that GUI. You might have saw my post earlier about how my the data wasn’t displaying on the GUI. Well I got the data to display on a GUI, but the number was extremely long, so I had to make a number abbreviation script to make the numbers shorter. Like turning, 10 millions into 10M. Well the script isn’t working and I’d love some help on how to fix it.
Module Script Titled “AbbreviateNumber” in Replicated Storage
local stats = game.Players.LocalPlayer.leaderstats:FindFirstChild("Coins")
local AbbreviateNumber = {}
local abbreviations = {
K = 4,
M = 7,
B = 10,
T = 13,
Qa = 16,
}
function AbbreviateNumber:Abbreviate(stats)
local text = tostring(math.floor(stats))
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(stats / 10 ^ (digits - 2)) * 10 ^ (digits - 2)
text = "$" .. string.format("%.1f", rounded / 10 ^ (digits - 1)) .. chosenAbbreviation
else
text = "$" .. stats
end
return text
end
return AbbreviateNumber
The Local Script in The Text Label Titled “Abbreviating Number”
local AbbreviateNumber = require(game.ReplicatedStorage.AbbreviateNumber)
local stats = game.Players.LocalPlayer.leaderstats:FindFirstChild("Coins") -- Change "Coins" To your sort of currency.
local text = AbbreviateNumber:Abbreviate(stats)
print(text)
script.Parent.Text = text
stats.Changed:Connect(function()
local x = stats.Value
script.Parent.Text = x
end)