Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't my price change with my other variable?

Asked by 4 years ago

So, I can buy the first one but when 'WeightLevel1' increases, the 'cost' doesn't. Can anyone help? I can buy it once with the first cost but I cant by anymore after that.

UpgradeBackpack.OnServerInvoke = function(player)
    local cost = player.UpgradeCosts.BackpackUpgrade
    if player.backpack.WeightLevel1.Value == 1 then
                cost.Value = 17  -- this works for the first cost
                player.backpack.Max.Value = 40
            player.backpack.NextUpgrade1.Value = 80
            elseif player.backpack.WeightLevel1.Value == 2 then
                cost.Value = 2
                player.backpack.Max.Value = 80
            player.backpack.NextUpgrade1.Value = 160

    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
    end

1 answer

Log in to vote
0
Answered by
zomspi 541 Moderation Voter
4 years ago

Try this

UpgradeBackpack.OnServerInvoke = function(player)
    local cost = player.UpgradeCosts.BackpackUpgrade
    if player.backpack.WeightLevel1.Value == 1 then
                cost.Value = 17  -- this works for the first cost
                player.backpack.Max.Value = 40
            player.backpack.NextUpgrade1.Value = 80
end
            if player.backpack.WeightLevel1.Value == 2 then
                cost.Value = 2
                player.backpack.Max.Value = 80
            player.backpack.NextUpgrade1.Value = 160
end
    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



Basically what I did is add "ends" after the if statements, the other if statements were only working if the first "if" was true, I think that's right anyways!

Ad

Answer this question