I have a Hud on roblox that shows your leader stats "Money,job, etc" But i want to script the money text so that if the amount of digits is greater than 3 there's a comma put for example " If the player just got 1000 i want the guis to display it as 1,000 not 1000. and so on for every number. 1,000 2,000 10,000 15,000 100,000,000 etc."
I know that i could just go into the script and say if the value == 1000 then gui.text = 1,000 but that would be way too much work as they players are going to be in the high digits. does anybody know how i can do this?
This script I created will add the "," after every three numbers. You might want to turn this into a function.
Edit:- this uses a string so you may need to convert any numbers to string use this To string.
I can explain how modulo work in more detail if you need it just comment at the bottom.
Hope this helps.
local str = "1234" --input string local output = "" --result str = string.reverse(str) --reverses the string so that the , go in the correct place for i=1 , string.len(str) do --loop through all characters if i % 4 == 0 then --uses modulo which is the remainder from the division of i/4 output = output .. "," .. string.sub(str, i, i) --adds in the , incuding the number else output = output .. string.sub(str, i, i) -- no , needed end end output = string.reverse(output) --puts the string back to its correct format print(output) -- prints the result
Closed as Not Constructive by M39a9am3R and Goulstem
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?