GUI not working in after a conditional

Basically here is my problem. I want to have a certain GUI element to be added if a certain condition is met but it does not seem to be working.
Here is my code:

function OnGUI()
{
	GUI.Label(Rect(80, 10, 50, 20), "Gold:");
	GUI.Label(Rect(130, 10, 50, 20), gold.ToString());
	
	if (gold >= 10 && numOfObjects < 6)
	{		
		gold -= 10;		
		if(slot1 == false)
		{
			GUI.Box(Rect(200, 10, 50, 20), "TEST");
			
			slot1 = true;
			numOfObjects++;
		}

First two GUI elements work but not the one that is dependant on the condition. If I move the GUI.Box code up, below the other GUI elements it works. Any ideas ? And by work btw I mean that the Box is not showing up on the screen.

At least part of your problem is here:

if (gold >= 10 && numOfObjects < 6)
{   
   gold -= 10;

OnGUI is executed every frame, so this will decrement gold by 10 every frame until it’s less than 10, after which that if will be false and it won’t even attempt to check slot1.

I got it. Problem is that the slot1 is being set to true right after the GUI box is created, which makes the box disappear immediately without even being seen. I will try to find another way to do what I want.