Int getting lost between functions

I am trying to make a buy menu for a project I’m working. I had a friend do the clientside stuff but the serverside is breaking for some reason. For some reason the Int I’m sending is getting “lost” after my if statement or is the incorrect value and taking too much money.



if (SERVER) then
	util.AddNetworkString("MetaDM_ShoppingBag")
	net.Receive("MetaDM_ShoppingBag",function(_,ply)
		print("[BuyMenuDebug]",ply:Nick().."Buying:",net.ReadInt(32),net.ReadString(),net.ReadInt(16))
		if ply:GetCoins() < net.ReadInt(32) then
			ply:PrintMessage(3,"You have insufficent funds to purchase the item(s).")
		else
			print("[BuyMenuDebug]",ply:Nick().."Cost ammount:",net.ReadInt(32))
			ply:TakeCoins(net.ReadInt(32))
			ply:PrintMessage(3,"Your purchase, "..net.ReadString().." (x"..net.ReadInt(16).."), was successful.")
		end
	end)
end


How the variables are being sent



BuyMenu.Internal.ShoppingBag.Network = function()
	for i = 1, #BuyMenu.ShoppingBag do
		net.Start("MetaDM_ShoppingBag")
			net.WriteInt(BuyMenu.ShoppingBag*.price,32)
			net.WriteString(BuyMenu.ShoppingBag*.item)
			net.WriteInt(BuyMenu.ShoppingBag*.amount,16)
		net.SendToServer()
	end
end


Any ideas why this wouldn’t be working the right way?

EDIT: Debug shows that it’s getting lost



[BuyMenuDebug]	Flex Buying:	100	Test	1
[BuyMenuDebug]	Flex Cost ammount:	0


Everything you are doing net.Read* on you need to save to a var. If you keep calling net.ReadInt(32), you’ll just be reading 32 bytes ahead of the last thing you read.

You can only read a value from net once. Store it in a variable. It’s a stack system.

[editline]hello[/editline]
Ah, ninja’d. This is why you refresh after opening so many tabs.

Never trust the client to tell you how much money they need to pay for an item. Doing that will ruin your economy because they can tell the server that the server needs to pay them per item, or simply use 0 per item.

Use a shared-table, and when the client wants to buy something, send the item id and the quantity. Run clientside checks to see if they have enough money but run the same checks on the server using the id and quantity.