Help with math problem: Upgrade System

Update: Cost was fixed but actual upgrade button doesnt work

This is the upgrade button script; it only takes away one upgrade worth and only adds one upgrade value

local player = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent
local debounce = false

script.Parent.MouseButton1Click:Connect(function()
if tonumber(script.Parent.Parent.TextBox.Text) ~= nil then
    if player.Stats.Cash.Value >= player.Stats["Robux Upgrade"].Value * 30 * (tonumber(script.Parent.Parent.TextBox.Text)) and debounce == false then
        debounce = true
        player.Stats.Cash.Value = player.Stats.Cash.Value - player.Stats["Robux Upgrade"].Value * 30 * (tonumber(script.Parent.Parent.TextBox.Text))
        player.Stats["Robux Upgrade"].Value = player.Stats["Robux Upgrade"].Value + tonumber(script.Parent.Parent.TextBox.Text)
        wait(0.1) 
        debounce = false
        end
    end
end)

This is the cost script;

local Short = require(game.ReplicatedStorage.Short)
while wait() do
  if tonumber(script.Parent.Parent.TextBox.Text) ~= nil then
    script.Parent.Text = "Cost: " .. Short.en(player.Stats["Robux Upgrade"].Value * 30 * (tonumber(script.Parent.Parent.TextBox.Text)))
  end
end

Can’t you just do price = price + 30? Are you wanting to charge more based on how much they want to upgrade? If not then just adding 30 would suffice.

You mean like adding a ‘-30’ and ‘+30’ button to increase the amount by 30?

For example they wanted to go from level 1 to level 5

H To here
30,60,90,120,150

It would be 30+60+90+120+150 or something similar to that,
but i cant put this into lua

Okay I see, so 30 per level. Then can’t you do price = 30*level?

But i want the input to be taken into consideration so they can upgrade … amount at a time

*I think i may have it, i X the number they entered onto that it seems to be working

Something like this?

local n = 0

for i = 1, 5 do
	n = n + 30
end

print(n) -- 150

Not sure what you are trying to say with

1 Like

That was just for the cost to show properly but the actual upgrade button is broke

This is the upgrade button script; it only takes away one upgrade worth and only adds one upgrade value

local player = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent
local debounce = false

script.Parent.MouseButton1Click:Connect(function()
if tonumber(script.Parent.Parent.TextBox.Text) ~= nil then
    if player.Stats.Cash.Value >= player.Stats["Robux Upgrade"].Value * 30 * (tonumber(script.Parent.Parent.TextBox.Text)) and debounce == false then
        debounce = true
        player.Stats.Cash.Value = player.Stats.Cash.Value - player.Stats["Robux Upgrade"].Value * 30 * (tonumber(script.Parent.Parent.TextBox.Text))
        player.Stats["Robux Upgrade"].Value = player.Stats["Robux Upgrade"].Value + tonumber(script.Parent.Parent.TextBox.Text)
        wait(0.1) 
        debounce = false
        end
    end
end)

This is the cost script;

local Short = require(game.ReplicatedStorage.Short)
while wait() do
  if tonumber(script.Parent.Parent.TextBox.Text) ~= nil then
    script.Parent.Text = "Cost: " .. Short.en(player.Stats["Robux Upgrade"].Value * 30 * (tonumber(script.Parent.Parent.TextBox.Text)))
  end
end