Help with buy button part 2

You guys didn’t respond to my last post except for one amazing fellow who tried to help, so here.

I am trying to make a shop, and the player can choose what amount of items to buy and the price changes along with the amount. Example: When the player selects, say 2 items, and the price of 1 item is $10, then the player will have to pay $10 x 2 = $20. However, when I try this, it reduces a lot more coins than it should. Example: when I select $20 dollars for 2 items, it reduces something like 100-200. Can you please help?

There are no errors.

Script:

function buy(v)
	if selectedTemp ~= nil then
		
		local coins = player.leaderstats.Coins
		

		local newval = (amnt.Value * v.Price.Value)
		
		print(amnt.Value)

			if coins.Value >= newval then
				local new = false
				if new ~= true and new == false then
					new = true
				coins.Value -= newval
				player.ItemsInStock[v.Name].Value += (amnt.Value)
					wait(.2)
					new = false
				end
			end
		end
end

Prints:

  15:17:31.059   ▼ 1 (x5)  -  Client - MainScript:25
     15:17:31.059     1
     15:17:31.060     1
     15:17:31.061     1
     15:17:31.062     1

There are no errors in the output. Thank you all!

What is selectedtemp? Also can you give more examples of the desired end product?

I guess you could try(not the actual code that you write in):

Local amountToDeduct = quantity X value

If coins >= amountToDeduct then
Coins - amountToDeduct
Else
Print(not enough coins)
End

Sorry for the bad formatting I am on mobile

selectedTemp is the button you select, like the button you pick in simulator shops that you click to see its info pop up in another frame.

My end product will be a bit like retail tycoon(1 not 2) 's buying system, where you can increase the amount you want to buy, and in doing so increasing the price as well.

Is this ok or not what you want?

Still has the same error(not in the output though), maybe it has something to do with the fact that when I printed amnt.Value it printed 5 times?

Try adding a cool down for the function?

i don’t know why but making the cooldown bigger fixed it? thanks