A buy all button in a simulator upgrade shop. How to implement it?

  1. What do you want to achieve? Keep it simple and clear!
    I want to create a buy all button in an upgrade thats called for example “+1 coin per click”. It increases the amount of coins you would need to buy it by 2 coins. Starting amount is 2.

  2. What is the issue? Include screenshots / videos if possible!
    I can’t seem to really find a way to calculate how many coins it would take to buy a specific amount of upgrades. Or in this case, buy all.

And no, im not using for loops since it would pretty much crash roblox if the user had like 1 billion coins which is possible in this game

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried looking at dev forums, spent an hour brain storming and still haven’t found a way to implement it.

Any help is appreciated.

1 Like

I’m pretty sure the only way to do this or the best way to do this is via for loops. Roblox WONT crash if they buy like 50 at a time. Roblox only crashes if it goes to the thousands. I’m pretty sure you wont have like 10k weapons. Try making a folder which has all your weapons, after that, insert a int value which will be called the price. Change the int value’s value to the price you want them to be. Then just loop through the weapons folder via a for in pair loop and if the player has enough coins it’ll give them the weapon, and remove the amount of coins they spent, simple.

But what if the user gets to the point where he has 100 billion coins and wants to buy all? Roblox surely won’t handle 1 billion cycles in a for loop.

Also its an upgrade shop where you can increase the amount of coins you get per click. Not a weapons shop

you wont have 1 billion stuff As long as you dont have a lot of stuff then roblox wont crash! Roblox crashes when it gets thousands of responses in a short amount of time.

Then add a wait() simple.

Read what i said. Again, i only have a upgrade that increases a NUMBER value (which is better than int value) when upgraded. Not a god damn objects shop

2 Likes

I was writing most of what I said before you added the edit.

So back to my point, I have an upgrade whereas the cost value increases by 2 every upgrade and the starting price is 2. So how do i calculate the total cost of it?

basically just send buyall in a remoteevent and have the server handle the inventory stuff

Its a number value upgrade. Not an item

that’s an arithmatic sequence, which is calculated like this:

d would be 2, a would be 2 and n would be the upgrade level. This will give you the total cost of the level needed.

If you want to find what level you need given money you’d need to do some basic Algebra I,

You’re given a, d but you need to solve for n.

For this example, the player is going to have 5000 coins to spend, and they want to upgrade to a certain level. This is where the math begins.

5000 = 2 + 2(n - 1)
  1. First you’re going to use reverse PEMDAS, where parentheses and exponents are first and you go from there.
  • We are going to distribute 2 to all of the values inside,
5000 = 2 + 2n - 2
  1. As you can see, there are two numbers that cancel out. Which is 2 and -2.
5000 = 2n
  1. We are left with 5000 = 2n which we can solve by dividing 2 on both sides.
5000/2 = 2n/2

Now we officially have the calculated our value which is 2500.

Pretty easy, huh?

Now here’s your formula:

n = math.floor(aₙ/2)

A more general formula would be probably this one:

n = math.floor((aₙ-(a - d))/d)

Keep in mind d is the price increase per level, a is the starting price.

Edit: General formula and math.floor bits

If you want the value of something to increase by 2 every time an example of it would be this -

-- this is just an example of how to multiply something.

value = Instance.new("NumberValue")
value.Parent = script

value2 = Instance.new("NumberValue")
value2.Parent = script
value2.Value = 100

value.Value = value2.Value * 2 -- 2 is the ammount multiplied by.

I assume you mean increase by a product of 2, not a literal increase of 2, but yes this is how that would be achieved. You may also want to set the value of “value” to an initial value of 0 otherwise it would be nil and could cause issues if referenced before assignment.

When a number value is created the value is automatically 0, you can test this if you create a value through a script and print() the value and it will show up as 0 and not nil.

Ah, you’re right, I thought only BoolValue had that behavior, the others all tend to be nil.

thank you very much, this is the most help i found. but what is the aₙ?