Kxghtism
(ThyFella)
July 26, 2020, 6:20pm
1
Hello there fellow robloxian.
I have some leaderstats called tix. And I’m trying to make it shorter so it shows…
1k+
Instead of it saying…
1000
So where my leaderstats script’s location is.
And the script for it is.
game.Players.ChildAdded:Connect(function(p)
local leaderstats = Instance.new("IntValue",p)
leaderstats.Name = "leaderstats"
local tix = Instance.new("StringValue", leaderstats)
tix.Name = "Tix"
end)
Any help is appreciated. Thank you and have a good day. I can’t explain very well due to language problems. Sorry
P.S: If your answer is correct and is functional, your message will be selected as a solution.
Blockzez
(Blockzez)
July 26, 2020, 6:27pm
2
I’d use logarithms by 1000 then divide the value, something like this.
local suffxes = {'k', 'M', 'B', 'T', ...}
local function shorten(value)
if value < 1000 then
return value
end
local i = math.min(math.floor(math.log(value, 1000)), #suffixes)
return math.floor(value / (1000 ^ i)) .. suffixes[i] .. '+'
end
3 Likes
Kxghtism
(ThyFella)
July 26, 2020, 6:31pm
3
Where do i position the code? in a script / local script or module script? or in server script storage or whatever.
Blockzez
(Blockzez)
July 26, 2020, 6:42pm
4
Wherever you prefer. I’d personally store it as a ModuleScript in the ReplicatedStorage, but it’s your choice.
Kxghtism
(ThyFella)
July 26, 2020, 6:51pm
5
I’ll try, thank you for the shortened leaderstats script.
un1ND3X
(ice)
July 26, 2020, 7:13pm
7
It works well, just the table was mispelled as suffxes instead of suffixes at the beginning - simply reading over the code solved this.
You could use open-source modules for this too, e.g:
local function shorten(Input)
local Negative = Input < 0
Input = math.abs(Input)
local Paired = false
for i,v in pairs(MoneyLib.Suffixes) do
if not (Input >= 10^(3*i)) then
Input = Input / 10^(3*(i-1))
local isComplex = (string.find(tostring(Input),".") and string.sub(tostring(Input),4,4) ~= ".")
Input = string.sub(tostring(Input),1,(isComplex and 4) or 3) .. (MoneyLib.Suffixes[i-1] or "")
Paired = true
break;
end
end
if not Paired then
local Rounded = math.floor(Input)
Input = tostring(Rounded)
end
This file has been truncated. show original
2 Likes