Sup, I’m looking for feedback on my leaderboard cash abbreviation script. Say for example your cash is 3759214
. To know how much money you have, you need to count the numbers, which is quite annoying, so I’ve made an abbreviation that script turns that number into 3.7M
. Now you can see how much money you’ve got at a glance.
I’ve seen other people use math, lookup tables, and all that, but here’s me just using if statements. I was wondering if my method is inefficient or if it’s just fine.
The script: localscript
plr = game.Players.LocalPlayer
local cash = plr:WaitForChild("plrStats"):WaitForChild("cash")
local function shortenFunc(ca) -- ca = cash
local c = string.split(tostring(ca), "")
if c == c then
if ca >= 1000000000 or ca < 1000 then -- we're only looking to abbreviate numbers between a billion and a thousand
return ca
elseif ca >= 100000000 then
if c[3] ~= "0" then
return "$"..c[1]..c[2]..c[3].."."..c[4].."M"
else
return "$"..c[1]..c[2].."M"
end
elseif ca >= 10000000 then
if c[3] ~= "0" then
return "$"..c[1]..c[2].."."..c[3].."M"
else
return "$"..c[1]..c[2].."M"
end
elseif ca >= 1000000 then
if c[2] ~= "0" then
return "$"..c[1].."."..c[2].."M"
else
return "$"..c[1].."M"
end
elseif ca >= 100000 then
if c[3] ~= "0" then
return "$"..c[1]..c[2]..c[3].."."..c[4].."K"
else
return "$"..c[1]..c[2].."K"
end
elseif ca >= 10000 then
if c[3] ~= "0" then
return "$"..c[1]..c[2].."."..c[3].."K"
else
return "$"..c[1]..c[2].."K"
end
elseif ca >= 1000 then
if c[2] ~= "0" then
return "$"..c[1].."."..c[2].."K"
else
return "$"..c[1].."K"
end
end
end
end
local function updateFunc()
script.Parent.Text = shortenFunc(cash.Value)
end
cash:GetPropertyChangedSignal("Value"):Connect(function()
updateFunc()
end)
repeat wait() until cash ~= nil
updateFunc()