# Charging system that increases per charge

Hello.

I’ve been making a game that uses spells. However, these spells require what I call mana. Now, to charge your mana, you must acquire it, and once you first acquire it, it is intended to be slow.

But the catch this, you can train how fast your mana charges by charging it fully many times.

This training process will be a long process, but over the course of 1000 max charges, you will have a very fast charge.

Example of a slow mana charge:
https://gyazo.com/a354f8b6a4acc28a47a61a21490075e4

And here’s an example of a fast charge:
https://gyazo.com/cb795c68d6423f3883631299ba92da7b

I have attempted to make a base of what is needed, however, I don’t have a good idea on how to proceed.

What I am basically trying to do is get an interger between the values 0.25 and 2, by using the amount of charges that a player has, which is 1 to 1000.

``````local BASE_MANA_CHARGE = .25
local MAX_MANA_CHARGE = 2

local function calculateChargeVal()
local fullCharges = playerData.FullCharges.Value

local total = BASE_MANA_CHARGE
local startingNum = fullCharges == 0 and BASE_MANA_CHARGE or fullCharges

total = (startingNum - BASE_MANA_CHARGE) / (MAX_MANA_CHARGE - BASE_MANA_CHARGE)

-- process of getting total charge amount here
total = math.clamp(total, BASE_MANA_CHARGE, MAX_MANA_CHARGE)
end
``````

Please tell me if there’s anything that is confusing. This is my first post.

1 Like

if you mean to have it charge faster the more you charge it, then, using your info, you first find the difference(1.75 seconds) of the two charges. then, you divide that by 1000 (0.00175 seconds).

So, if you want it to be faster every charge, the math formula is like this:

``````2 - (FullCharges * (1.75/1000))
``````
1 Like

This equation works, but it doesn’t work in the way I wish. Instead, the formula gives me an answer that is reversed to how I want it to be, as replacing ‘FullCharges’ with 1000 will result in a .25 (instead of 2), and 1 will result in a 2 (instead of .25).

You would just edit TOP_Crundee123’s formula into this :

``````.25 + ((FullCharges - 1) * (1.75/1000))
``````

I also don’t really understand what you are trying to do so sorry if its wrong.

1 Like

Oh, I thought you meant the more charges the faster it is. Well, you can reverse that simply

`0.25 + (FullCharges * (1.75/1000))`