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

Shortening Currencies Value Doesn't Work For Second Currency?

Asked by 5 years ago

I'm trying to shorten the values for the currency,

It works for Coins but no the Chi?

Leaderstats

01game.Players.PlayerAdded:Connect(function(plr)
02    local leaderstats = Instance.new("Folder", plr)
03    leaderstats.Name = "leaderstats"
04 
05    local MainCurrency = Instance.new("Folder", plr)
06    MainCurrency.Name = "MainCurrency"
07 
08    local Coins = Instance.new("IntValue", MainCurrency)
09    Coins.Name = "Coins"
10    Coins.Value = 0
11 
12    local Chi = Instance.new("IntValue", MainCurrency)
13    Chi.Name = "Chi"
14    Chi.Value = 0
15 
View all 63 lines...
0
Your using 2 while loops, so the first while loop will only run, try combining the loops. killerbrenden 1537 — 5y
0
Any errors? moo1210 587 — 5y
0
No errors Jomeliter 55 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

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.

01local numericalShortener = {}
02 
03function numericalShortener.ShortenChi(player)
04    local chi = tostring(player:WaitForChild("MainCurrency"):FindFirstChild("Chi").Value)
05    local chiDis = player:WaitForChild("leaderstats"):FindFirstChild("Chi")
06 
07    if #chi >= 10 then
08        chiDis.Value = chi:sub(0,(#chi - 9)).."."..(chi:sub(#chi - 7,(#chi - 7))).."B+"
09    elseif #chi >= 7 then
10        chiDis.Value = chi:sub(0,(#chi - 6)).."."..(chi:sub(#chi - 5,(#chi - 5))).."M+"
11    elseif #chi >= 4 then
12        chiDis.Value = chi:sub(0,(#chi - 3)).."."..(chi:sub(#chi - 2,(#chi - 2))).."K+"
13    else
14        chiDis.Value = chi
15    end
View all 33 lines...

In a ServerScript that I named CurrencyHandler I added a loop for the functions of the ModuleScript while requiring it.

01local moduleShortener = require(script.NumericalShortener)
02 
03game.Players.PlayerAdded:Connect(function(plr)
04    local leaderstats = Instance.new("Folder", plr)
05    leaderstats.Name = "leaderstats"
06 
07    local MainCurrency = Instance.new("Folder", plr)
08    MainCurrency.Name = "MainCurrency"
09 
10    local Coins = Instance.new("IntValue", MainCurrency)
11    Coins.Name = "Coins"
12    Coins.Value = 0
13 
14    local Chi = Instance.new("IntValue", MainCurrency)
15    Chi.Name = "Chi"
View all 42 lines...

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!

0
I put a ServerScript inside of ServerScriptService, and then I put a ModuleScript inside of that ServerScript. killerbrenden 1537 — 5y
0
Thx, it works! Jomeliter 55 — 5y
0
No problem! killerbrenden 1537 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Tried This But The Chi's Value Won't Change Now?

01game.Players.PlayerAdded:Connect(function(plr)
02    local leaderstats = Instance.new("Folder", plr)
03    leaderstats.Name = "leaderstats"
04 
05    local MainCurrency = Instance.new("Folder", plr)
06    MainCurrency.Name = "MainCurrency"
07 
08    local Coins = Instance.new("IntValue", MainCurrency)
09    Coins.Name = "Coins"
10    Coins.Value = 0
11 
12    local Chi = Instance.new("IntValue", MainCurrency)
13    Chi.Name = "Chi"
14    Chi.Value = 0
15 
View all 60 lines...

Answer this question