Your using 2 while loops, so the game reads it from top to bottom, and it will loop over the first While Loop until it breaks. If it doesn't break, it'll just loop over that current code for the rest of the game being live.
To fix this, I used a ModuleScript with functions and just looped those. I may have done it a bit more complicated and memory consuming than it had to be, but I just found this way to be easier for me.
In the ModuleScript that I named NumericalShortener I changed it around.
01 | local numericalShortener = { } |
03 | function numericalShortener.ShortenChi(player) |
04 | local chi = tostring (player:WaitForChild( "MainCurrency" ):FindFirstChild( "Chi" ).Value) |
05 | local chiDis = player:WaitForChild( "leaderstats" ):FindFirstChild( "Chi" ) |
08 | chiDis.Value = chi:sub( 0 ,(#chi - 9 )).. "." ..(chi:sub(#chi - 7 ,(#chi - 7 ))).. "B+" |
10 | chiDis.Value = chi:sub( 0 ,(#chi - 6 )).. "." ..(chi:sub(#chi - 5 ,(#chi - 5 ))).. "M+" |
12 | chiDis.Value = chi:sub( 0 ,(#chi - 3 )).. "." ..(chi:sub(#chi - 2 ,(#chi - 2 ))).. "K+" |
18 | function numericalShortener.ShoternCoins(player) |
19 | local coins = tostring (player:WaitForChild( "MainCurrency" ):FindFirstChild( "Coins" ).Value) |
20 | local coinsDis = player:WaitForChild( "leaderstats" ):FindFirstChild( "Coins" ) |
23 | coinsDis.Value = coins:sub( 0 ,(#coins - 9 )).. "." ..(coins:sub(#coins - 7 ,(#coins - 7 ))).. "B+" |
24 | elseif #coins > = 7 then |
25 | coinsDis.Value = coins:sub( 0 ,(#coins - 6 )).. "." ..(coins:sub(#coins - 5 ,(#coins - 5 ))).. "M+" |
26 | elseif #coins > = 4 then |
27 | coinsDis.Value = coins:sub( 0 ,(#coins - 3 )).. "." ..(coins:sub(#coins - 2 ,(#coins - 2 ))).. "K+" |
29 | coinsDis.Value = coins |
33 | return numericalShortener |
In a ServerScript that I named CurrencyHandler I added a loop for the functions of the ModuleScript while requiring it.
01 | local moduleShortener = require(script.NumericalShortener) |
03 | game.Players.PlayerAdded:Connect( function (plr) |
04 | local leaderstats = Instance.new( "Folder" , plr) |
05 | leaderstats.Name = "leaderstats" |
07 | local MainCurrency = Instance.new( "Folder" , plr) |
08 | MainCurrency.Name = "MainCurrency" |
10 | local Coins = Instance.new( "IntValue" , MainCurrency) |
14 | local Chi = Instance.new( "IntValue" , MainCurrency) |
18 | local CoinsDis = Instance.new( "StringValue" , leaderstats) |
19 | CoinsDis.Name = "Coins" |
22 | local Gems = Instance.new( "IntValue" , leaderstats) |
26 | local ChiDisp = Instance.new( "StringValue" , leaderstats) |
30 | local Strength = Instance.new( "IntValue" , leaderstats) |
31 | Strength.Name = "Strength" |
34 | local MaxStrength = Instance.new( "IntValue" , leaderstats) |
35 | MaxStrength.Name = "MaxStrength" |
36 | MaxStrength.Value = 10 |
39 | moduleShortener.ShortenChi(plr) |
40 | moduleShortener.ShoternCoins(plr) |
This is how I have it set up in ServerScriptService, here.
Hope this helped! I'm pretty sure this should work as I have tested it myself.
If this is what you're looking for and it helped, let me know by selecting this as the answer!