So currently I’m trying to calculate what the next upgrade will cost for a player depending on their current level. For example within my game there is a speed upgrade that decided how fast you get in game cash and every time you upgrade it it goes down by 0.1, so if the base speed was 10 and you get a upgrade it is now 9.9. With that in mind how would I go about calculating the next upgrade, lets say it’s 1k for the first upgrade how will I automatically double that to 2k for the next upgrade without storing each upgrade and its cost within a table and just basing it off their current. Here is what I tried but it doesn’t work. (10 + (10 - Upgrades.Speed)) * 1000
You can get the incremented amount by storing the initial value in a variable and multiplying it by the difference in initial speed and current.
e.g.
local baseSpeed = 10
local speed = 9.5
local upgradeCost = 1000
local function calculateUpgradePrice()
return math.abs(baseSpeed - speed) * 10 * upgradeCost
end
The upgrade cost, when the speed is 9.5, would be 5000.