Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

2 answers

✓ Accepted answer

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.

6 comments

0

btw this is a local script :D

0

Use WaitForChild. Also, why do you make a function solely to call another function with no new arguments in your Connect?

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.

0

Thank you dude!

0

I didn't post a new answer and instead downvoted because that's the point of the downvote button

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

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"

This discussion is preserved as it was. New answers, comments, and votes are closed.