Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.