My GUI button on displays a log but doesn't change my float

I’m trying to get the button to take the cost of the item away from the money the player has but this doesn’t seem to work. I’m new here so it may be extremely obvious but if you can fix it please explain what I did wrong if you can
thanks

using UnityEngine;
using System.Collections;

public class Score : MonoBehaviour {

public Texture btnTexture;

//START ITEM LIST
public float spoonDropsPerSecond = 1f;
public float spoonCost = 5000f;
//END ITEM LIST


public float startingDrops = 10f;
public float dropsCount = 0f;

bool menuOpen;

public float dropsPerSecond;
public float dropsMultiplier;
public float totalDropsPerSecond;

// Use this for initialization
void Start () {

	Screen.showCursor = false;
	
	dropsCount = startingDrops;
	menuOpen = false;
	dropsPerSecond ++;
}

// Update is called once per frame
void Update () {

	totalDropsPerSecond = dropsPerSecond * (1 + dropsMultiplier);

	dropsCount = dropsCount + totalDropsPerSecond * (Time.deltaTime * 1);

	//remove before release
	if (Input.GetKeyDown (KeyCode.Z)) {
		dropsCount = 1000000f;		
	}

	if (Input.GetKeyUp (KeyCode.Tab)) {
		if (menuOpen == false) {
			menuOpen = true;
			Screen.showCursor = true;
		}
		else if (menuOpen == true) {
			menuOpen = false;
			Screen.showCursor = false;
		}
	}

	

//this is how I am displaying larger number but I removed some of the code

if (dropsCount < 1000) {
		guiText.text = "Drops: " + dropsCount.ToString ("F0") + "                              DPS: " + dropsPerSecond.ToString("F0") + "                              Multiplier: x" + dropsMultiplier.ToString("F0") + "                              Total DPS " + totalDropsPerSecond.ToString("F0");
	}

	if(Input.GetKeyDown(KeyCode.Escape)){
		Application.Quit();
	}

}

void OnGUI(){

	if (menuOpen == true) {

		GUI.Box(new Rect( 0, 0, 900, 25),"Instructions: Press the corrosponding key to buy one for the price stated. To access lower levels you must purchase the upgrade at the end of the level");

	
		if (GUI.Button (new Rect ( 20, 70, 220, 25), "test spoon click")){
			if ( dropsCount >= spoonCost){
				Debug.Log("this works");
				dropsCount = dropsCount - spoonCost;
				dropsPerSecond = dropsPerSecond + spoonDropsPerSecond;
			}
		}


		//GUI.Box(new Rect( 20, 70, 220, 25),"Spoon, 5000 Drops, +1 DPS");

	}
}

}

Hi,

I’m not so experienced yet, but I do note that in the code provided, the script doesn’t actually assign any values to the money or the itemCost variables.

So, from what it looks like, it’s saying that “money” & “itemCost” exist, at the start, then in the OnGUI part, you’re checking if money (which equals, I believe =0) and itemCost (which also equals 0 ) are the same (or money is more than itemCost), which is True, 'cause both are 0.
Then it prints the Debug.Log “this works”, and then tries to make the value of money to equal money (0) - itemCost (also 0) … so, it kind of ends up in 0-0=…0

Perhaps try adjusting the variables at the top of the script to:

public float money = 20f;

&

public float itemCost = 13f;

(for example)

(Don’t forget the “f” part of the value, since this is a float!)

Hope this helps!

Check your Inspector window.
I suspect that you may have changed the value of the public variables somewhere somehow.

The values in the script are default values, actual values can be changed by other scripts or manually in Inspector