If I just leave the value at 17 or in the script put cost.Value = Max.Value *2 or something like that it will work. But for some reason it will not work like this. The original cost is 17 and the value changes but the cost stays the same. Help please
Button script and cost script
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
local upgrade = game.ReplicatedStorage.Functions.UpgradeBackpack:InvokeServer()
if upgrade == false then
script.Parent.Text = "You need more coins!"
wait(1)
script.Parent.Text = "Upgrade"
elseif upgrade == true then
script.Parent.Text = "Upgraded!"
wait(1)
script.Parent.Parent.Parent.Parent.Parent.Parent.Visible = false
script.Parent.Text = "Upgrade"
local cost = player.UpgradeCosts.BackpackUpgrade
if player.backpack.WeightLevel1.Value == 2 then
cost.Value = 20
player.backpack.Max.Value = 80
player.backpack.NextUpgrade1.Value = 160
end
if player.backpack.WeightLevel1.Value == 3 then
cost.Value = 21
player.backpack.Max.Value = 160
player.backpack.NextUpgrade1.Value = 200
end
if player.backpack.WeightLevel1.Value == 4 then
cost.Value = 22
player.backpack.Max.Value = 200
player.backpack.NextUpgrade1.Value = 210
end
if player.backpack.WeightLevel1.Value == 5 then
cost.Value = 23
player.backpack.Max.Value = 210
player.backpack.NextUpgrade1.Value = 230
end
if player.backpack.WeightLevel1.Value == 6 then
cost.Value = 24
player.backpack.Max.Value = 230
player.backpack.NextUpgrade1.Value = 250
end
if player.backpack.WeightLevel1.Value == 7 then
cost.Value = 25
player.backpack.Max.Value = 250
player.backpack.NextUpgrade1.Value = 300
end
if player.backpack.WeightLevel1.Value ==8 then
cost.Value = 26
player.backpack.Max.Value = 300
player.backpack.NextUpgrade1.Value = 301
end
if player.backpack.WeightLevel1.Value == 9 then
cost.Value = 27
player.backpack.Max.Value = 301
player.backpack.NextUpgrade1.Value = 302
end
if player.backpack.WeightLevel1.Value == 10 then
cost.Value = 28
player.backpack.Max.Value = 302
player.backpack.NextUpgrade1.Value = 303
end
if player.backpack.WeightLevel1.Value == 11 then
cost.Value = 29
player.backpack.Max.Value = 303
player.backpack.NextUpgrade1.Value = 304
end
if player.backpack.WeightLevel1.Value == 12 then
cost.Value = 30
player.backpack.Max.Value = 304
player.backpack.NextUpgrade1.Value = 305
end
if player.backpack.WeightLevel1.Value == 13 then
cost.Value = 31
player.backpack.Max.Value = 305
player.backpack.NextUpgrade1.Value = 306
end
if player.backpack.WeightLevel1.Value == 14 then
cost.Value = 32
player.backpack.Max.Value = 306
player.backpack.NextUpgrade1.Value = 307
end
if player.backpack.WeightLevel1.Value == 15 then
cost.Value = 33
player.backpack.Max.Value = 307
player.backpack.NextUpgrade1.Value = 308
end
if player.backpack.WeightLevel1.Value == 16 then
cost.Value = 34
player.backpack.Max.Value = 308
player.backpack.NextUpgrade1.Value = 309
end
if player.backpack.WeightLevel1.Value == 17 then
cost.Value = 35
player.backpack.Max.Value = 309
player.backpack.NextUpgrade1.Value = 310
end
if player.backpack.WeightLevel1.Value == 18 then
cost.Value = 36
player.backpack.Max.Value = 310
player.backpack.NextUpgrade1.Value = 311
end
if player.backpack.WeightLevel1.Value == 19 then
cost.Value = 37
player.backpack.Max.Value = 311
player.backpack.NextUpgrade1.Value = 312
end
if player.backpack.WeightLevel1.Value == 20 then
script.Parent.Text = "MAX!"
script:Destroy()
end
end
end)
upgrade script
UpgradeBackpack.OnServerInvoke = function(player)
local cost = player.UpgradeCosts.BackpackUpgrade
if cost.Value <= player.leaderstats["Coins"].Value then
player.leaderstats["Coins"].Value = player.leaderstats["Coins"].Value -cost.Value
player.backpack.WeightLevel1.Value = player.backpack.WeightLevel1.Value + 1
return true
else
return false
end
end
Thanks

2 comments
How do I make the 'Upgrade Script' detect when the value is being updated
I don't understand what the question you're asking is, but if you want the 'Upgrade Script' to detect when the value is updated, you could use the 'Changed' event from the ROBLOX API. You can read about it here: https://developer.roblox.com/en-us/api-reference/event/Instance/Changed