Currency System (Copper, Silver, Gold) Distribution?

Hello! So i have a currency system in my game… and the code within the gui that shows it looks like thie: Note that the name of the currency is “Aires”

local player = game.Players.LocalPlayer
local CharVals = player:WaitForChild("CharacterStats")
local Aires = CharVals:WaitForChild("Aires")
local CopperIcon = script.Parent.Copper.NumberRing.Number.Nuum
local SilverIcon = script.Parent.Silver.NumberRing.Number.Nuum
local GoldIcon = script.Parent.Gold.NumberRing.Number.Nuum

CopperIcon.Text = Aires.Value
SilverIcon.Text = math.floor(Aires.Value/100)
 GoldIcon.Text = math.floor(Aires.Value/10000)

Aires.Changed:Connect(function()
    CopperIcon.Text = Aires.Value
    SilverIcon.Text = math.floor(Aires.Value/100)
    GoldIcon.Text = math.floor(Aires.Value/10000)
end)

This works great! 100 copper = 1 silver, 100 silver = 1 gold

However, i’d like to make it so that if you reach 100 copper, instead of continuously adding more of the copper aires, it resets to 0 or whatever denomination is left over between the silver aires, and likewise with silver to gold… so that if you have 100 Aires, it will display as 0 copper, and 1 silver. Or if you have 145 Aires, it will display as 45 copper and 1 silver.

Any thoughts? THANKS! :slight_smile:

1 Like

I don’t know how well it’d work, but you could try instead

Aires.Changed:Connect(function()
    local Coins = Aires.Value
    local Gold = math.floor(Coins/10000)
    Coins = Coins - Gold * 10000
    local Silver = math.floor(Coins/100)
    Coins = Coins - Silver * 100
    local Copper = Coins
    -- then set the text fields accordingly.
end)

I suggested this because you aren’t reducing the starting value after calculating how many gold etc you have.