Hi, so I got a script that is supposed to be a “short” script to make numbers write as “1m” for example and not 1000000. Here’s the code:
local table = {"", "k", "m"} -- Continue the table with abbreviations you want
module.short = function(value)
local abbrev = math.floor(math.log(value, 1e3))
return math.floor(value * 1e2) / (1e2 * 1e3 ^ (abbrev - 1))..table[abbrev]
end
The problem is that I have no idea if this is the entire script for it to work and I don’t know how to use it.
I know this is kinda weird for a question but I hope you understand what I mean.
Hi, this exact question gets asked pretty often and there are standard solutions out there if you give it a search, so you might want to look at those for more info.
You probably shouldn’t overwrite the table builtin variable unless you know what you’re doing. “suffixes” is a better name.
Try print(module.short(10000)), print(module.short(1000000)) and print(module.short(1000000000)). The last one should fail because the function is not done.
Okay but I mean, how could I use it in other scripts if I want for example to make a UI with a stat on it. The script is already done but how could I implement the short script in it for it to display suffixes like 1m
local numberAbbreviator = require(daModule) --this variable now holds the "module.short" function from the ModuleScript, because that's what it returned
local money = 1238120938123
local moneyLabel = ...
function updateMoneyLabel()
moneyLabel.Text = ("%s $"):format(numberAbbreviator(money))
end
... when the money changes, update the money label by calling updateMoneyLabel