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

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

Asked by
zed_103 23
4 years ago

so im trying to make a game that if you have a 1,000 coins it will be replaced to 1K coins

0
@AetherProgrammer I like it and will probably use that approach in the future. I won't change my answer for readability sake. SteelMettle1 394 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago
Edited 4 years ago

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)

0
where do i put that script zed_103 23 — 4y
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. SteelMettle1 394 — 4y
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" SteelMettle1 394 — 4y
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. XviperIink 428 — 4y
Ad

Answer this question