Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make value like 57,394 to 57.3K? I cant get it!

Asked by 4 years ago
Edited 4 years ago

I really have know idea of how to make this. The other people arent LISTING WHERE TO PUT IT.

Is it like: If i. Leaderstats.value = 1000 do text = "1k"

0
Probably because you have not said where do you need it. We are not clairvoyants. sleazel 1287 — 4y
0
Sadly "LocalPlayer" says 'nil' value SharkOwen_dev 69 — 4y

2 answers

Log in to vote
-1
Answered by
VitroxVox 884 Moderation Voter
4 years ago

Hey dude i don't know if this works anymore cause i used it a long time ago, but here give it a try:

local function comma_value(amount) -- Stolen from here http://lua-users.org/wiki/FormattingNumbers
  local formatted = amount
  while true do  
    formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
    if (k==0) then
      break
    end
  end
  return formatted
end 

local function formatTokens(amount)
    if game.Players.LocalPlayer.leaderstats.Tokens.Value > 100000000 then
        return comma_value(amount/1000000).."M"
    elseif game.Players.LocalPlayer.leaderstats.Tokens.Value >= 100000 then
        return comma_value(amount/1000).."K"
    else
        return comma_value(amount)
    end
end

local function refreshTokenText()
    --[[if game.Players.LocalPlayer.leaderstats.Tokens.Value > 99999 and game.Players.LocalPlayer.leaderstats.Tokens.Value < 1000000  then
        script.Parent.Text = comma_value(game.Players.LocalPlayer.leaderstats.Tokens.Value/100000) .."K"
    end
    if game.Players.LocalPlayer.leaderstats.Tokens.Value > 999999 then
        script.Parent.Text = comma_value(game.Players.LocalPlayer.leaderstats.Tokens.Value/1000000) .."M"
    end
    if game.Players.LocalPlayer.leaderstats.Tokens.Value < 100000 then
        script.Parent.Text = comma_value(game.Players.LocalPlayer.leaderstats.Tokens.Value)
    end]]--
    script.Parent.Text = formatTokens(game.Players.LocalPlayer.leaderstats.Tokens.Value)
end

repeat wait() until game.Players.LocalPlayer:FindFirstChild("leaderstats") and game.Players.LocalPlayer:FindFirstChild("leaderstats"):FindFirstChild("Tokens")
refreshTokenText()
game.Players.LocalPlayer.leaderstats.Tokens.Changed:Connect(function()
    refreshTokenText()
end)

Of course you need to change things inside, example as "Tokens" and other stuff."

if worked or helped please accept, comment if there's a problem.

0
btw this is a local script :D VitroxVox 884 — 4y
0
Use WaitForChild. Also, why do you make a function solely to call another function with no new arguments in your Connect? hiimgoodpack 2009 — 4y
0
If you have a problem with my answer think about how you didn't post an answer if you didn't i wouldn't have to and this wouldn't happen, if you don't like my answer just post your own smh. VitroxVox 884 — 4y
0
Thank you dude! SharkOwen_dev 69 — 4y
View all comments (2 more)
0
I didn't post a new answer and instead downvoted because that's the point of the downvote button hiimgoodpack 2009 — 4y
0
"downvote button" bruh like i said if you don't like something at least give a reason to it, i'm sayin if you don't like my answer then fliping answer yourself! no worries tho i see you! :D VitroxVox 884 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Literally just check the lenght of the number and in case it has more than a number then just keep first numbers and add a "k"

Answer this question