Need help with a shop script.. :/

The problem is, let’s say an example:

I have 10 coins. 5 Health costs 5 coins. I have 10/20 health. And when i buy the health, i buy to full, and use all my money.

How can i make it only buy is ONCE?
Here’s the piece of my code that uses the shop:

function OnGUI () {
	if(insideEngine == true) {
	GUI.Box (Rect (500,400,100,70), "Press F to

Fix Engine
Cost: 5M");
if(Input.GetKeyDown(“f”)) {
if(Stats.scrapMetal > 5) {
if(Stats.shipHealth < 1000) {
Stats.scrapMetal -= 5;
Stats.shipHealth += 100;
}
}
}
}
}

OnGUI is called more than once within a frame. Most frames it will be called at least twice, once for each event (read up on GUI events to learn more), where the final event is a repaint event. Each time it’s called, the Inputs will be identical. Move your Input check to Update, which is only called once per frame.