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

how to make a 1,000 coins is will be 1K coins?

1 answer

You will have to do something like this:

local coins = 8985923
local simplifyCoins = 0

if coins > 999999 then
	simplifyCoins = coins / 1000000
	-- coins above 999,999 will now show up in the format: 5.5
	simplifyCoins = math.floor(simplifyCoins * 100)/100
	--rounds number down to 2 decimal places
	simplifyCoins = tostring(simplifyCoins)
	-- turn it into a string
	print(simplifyCoins)
	print(simplifyCoins.."M")
	
elseif coins > 999 then
	simplifyCoins = coins / 1000
	--coins above 999 will now show up in the format: 5.5
	simplifyCoins = math.floor(simplifyCoins * 100)/100
	--rounds number to 2 decimal places
	simplifyCoins = tostring(simplifyCoins)
	-- turn it into a string
	print(simplifyCoins.."K")
end

Prints

--8.98
--8.98M

basically you just check to see how high coins is, then divide it by whatever place it falls on, then concatenate an "M" or "K".

[EDIT] I made it round down 2 decimal places to make it easier to read for the larger numbers. Also,I would put the repeated code inside of a function that is called within the if statements to avoid repeating the same code (that would be a lot of wasted lines if you went up to quintillions)

5 comments

0

where do i put that script

0

I have no way of knowing exactly where to put it in your code. It should be where you want this simplification to occur. If you want it to appear in a leaderboard or something, then it should be in a server script. If you want it in a player's GUI then it should be in a local script.

0

Also, the prints are just to show you how to concatenate the K or M. Instead of the prints you'll probably make a textLabel.Text equal to simplifyCoins.."K"

0

You could properly put the script into a module an having the script to call for it. https://developer.roblox.com/en-us/api-reference/class/ModuleScript Also put the module script into a place where both the client and server can see it unless you just want to handle everything on the server and not the client.

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