Hello, fellow beginner here.So i am trying to add cash to my game and i want to abbreviate the numbers using suffixes like K for thousand M for million and so on. And i do know that i didnt attempt it it is because i dont know how to, So please help
To put a string after a number, you can use ..
To figure out which suffix you need, you can use a loop and a table.
The logic: If a number is divided by 1000 and it is bigger than 1, it means it's still too big for the current suffix, if you loop this you can easily get the correct suffix.
local List = { "K","M","B","T","Qd","Qn","Sx","Sp","O","N" --List of your suffixes in order of 1000's } function NumberSuffix(Num) local ListCount = 0 -- while we're not at the correct suffix do while Num / 1000 >= 1 do -- increment the suffix from the array ListCount = ListCount + 1 -- divide the number so we can continue with it. Num = Num / 1000 end -- if the initial number was < 1000 return the number. if ListCount == 0 then return Num end -- returns the number, with the suffix added at the end return math.floor(Num*10)/10 ..List[ListCount].."+" end local f = NumberSuffix print(f(5)) --> 5 print(f(1337)) --> 1.3K+ print(f(30203)) --> 30.2K+ print(f(32482348324832)) --> 32.4T+ print(f(248738492384293483294823984234)) --> 248.7O+
--Local Script--
local plr = game.Players.LocalPlayer local cashNum = tonumber(plr.Cash.Value) if plr.Cash >=1000 plr.Cash = tostring(cashNum/1000).."K" end if plr.Cash >=1000000 then plr.Cash = tostring(cashNum/1000000).."M" end
If you want to keep going use this
if plr.Cash >= --[[Number you want to convert]] then plr.Cash = tostring(cashnum/--[[Number you want to convert]])..--Abbreviation end
also make sure the cash value type is a string or else it won't work.