Bool not working correctly, thinks that it's false even though it's true

Hey guys I’m driving myself crazy with this issue so I would love some help.

using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Security.Cryptography;
using UnityEngine;

public class RoomSpawner : MonoBehaviour
{
    [Tooltip("The seed that Room will be generated with. Set to a value %lt 0 to have the seed generated randomly on build/generation.")]
    public int seed = -1;

    public int openingDirection;
    // 1 --> need bottom door
    // 2 --> need top door
    // 3 --> need left door
    // 4 --> need right door

    private RoomTemplates templates;
    private AddRoom add;
    private int rand;
    public bool spawned = false;

    private float waitTime = 20f;
    private RoomMax nr;
    private SetSeed sSeed;

    void Start()
    {
        //sSeed = GameObject.FindGameObjectWithTag("MainRooms").GetComponent<SetSeed>();
        //UnityEngine.Random.InitState(sSeed.seed);
        //causing the EnemySpawner to have the same seed;

        //Destroy(gameObject, waitTime);
        templates = GameObject.FindGameObjectWithTag("MainRooms").GetComponent<RoomTemplates>();
        add = gameObject.GetComponentInParent<AddRoom>();
        Invoke("Spawn", 1f);
        nr = GameObject.FindWithTag("MainRooms").GetComponent<RoomMax>();
    }

    void Spawn()
    {

        if (templates == null)
        {
            UnityEngine.Debug.Log("templates not been set");
        }
        if (spawned == false)
        {
            if (nr.numberRoom <= nr.maxRoom)
            {
                if (openingDirection == 0)
                {
                }
                if (openingDirection == 1)
                {
                    rand = Random.Range(0, templates.bottomRooms.Length);
                    Instantiate(templates.bottomRooms[rand], transform.position, templates.bottomRooms[rand].transform.rotation);
                    nr.numberRoom += 1f;
                }
                else if (openingDirection == 2)
                {
                    rand = Random.Range(0, templates.topRooms.Length);
                    Instantiate(templates.topRooms[rand], transform.position, templates.topRooms[rand].transform.rotation);
                    nr.numberRoom += 1f;
                }
                else if (openingDirection == 3)
                {
                    rand = Random.Range(0, templates.leftRooms.Length);
                    Instantiate(templates.leftRooms[rand], transform.position, templates.leftRooms[rand].transform.rotation);
                    nr.numberRoom += 1f;
                }
                else if (openingDirection == 4)
                {
                    rand = Random.Range(0, templates.rightRooms.Length);
                    Instantiate(templates.rightRooms[rand], transform.position, templates.rightRooms[rand].transform.rotation);
                    nr.numberRoom += 1f;
                }
                spawned = true;
                //UnityEngine.Debug.Log(rand + " " + transform.position);
            }
            if (nr.numberRoom > nr.maxRoom)
            {
                templates.allDone = true;
                Invoke("SpawnClose", 1f);
            }
        }
    }

    void SpawnClose()
    {
        if (spawned == false)
        {
            if (nr.numberRoom > nr.maxRoom)
            {
                if (openingDirection == 1)
                {
                    Instantiate(templates.ClosedbottomRooms, transform.position, templates.ClosedbottomRooms.transform.rotation);
                }
                else if (openingDirection == 2)
                {
                    Instantiate(templates.ClosedtopRooms, transform.position, templates.ClosedtopRooms.transform.rotation);
                }
                else if (openingDirection == 3)
                {
                    Instantiate(templates.ClosedleftRooms, transform.position, templates.ClosedleftRooms.transform.rotation);
                }
                else if (openingDirection == 4)
                {
                    Instantiate(templates.ClosedrightRooms, transform.position, templates.ClosedrightRooms.transform.rotation);
                }
                spawned = true;
            }
        }
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("SpawnPoint"))
        {
            if (spawned == false && other.GetComponent<RoomSpawner>().spawned == false)
            {
                Instantiate(templates.closedRooms, transform.position, templates.closedRooms.transform.rotation);
                Destroy(gameObject);
                spawned = true;
            }

            /*if (spawned == false && other.GetComponent<RoomSpawner>().spawned == true)
            {
                UnityEngine.Debug.Log("Worked" + " " + transform.position);
                spawned = true;
            }*/
        }
    }
}

On line 127, it’s supposed to only say “Worked” if spawned = false, but for some reason it thinks that every room tile is spawned = false even after they should equal spawned = true. It’s hard to explain the whole problem I can add to it if anyone asks. Thank you

You only ever set the bool to true in that script so as it is public, where else it is referenced? Is another script setting it to false?

I’m confused because you are destroying the gameObject the script is on, yet setting spawned = true right after. What are you trying to accomplish with that?

The commented code when uncommented, are you saying it always runs?

shoot I meant to delete that and forgot to sorry about that

yes, the commented code when un commented will run when the game object that it’s on hits another game object that has the same script. It will then compare the two seeing which is spawned = true/false and then determine an action

There’s several of these scripts, they’re supposed to compare to one and another

So, the gameobject this script is on when it collides with a SpawnPoint checks if it’s condition is false and the only determining factor for the if checks is if the other script is true or false.

I’m trying to understand what issue you are running into. Is it one if statement isn’t ever running? If that is the case, make sure you are debugging what the other scripts spawned value is.

Also, what @WarmedxMints_1 was saying is the value of spawned starts as false but ONLY gets set to true in the script and never back to false, which means that once it’s true it is always true unless being changed by another script.

yes true

that’s the thing, it’s ALWAYS saying it’s “worked” for each object. Which is weird because the object has already spawned something and should be true not false.

yes I want it to stay true, it determines which rooms have been placed and which haven’t

Have you added a debug to the OnTrigger call to print out what value spawned is?

I should do that, I’ll do it when I get back home to my laptop

do you not need to set the other script object to true as well?

I set it to true if it spawns a room, I’m trying to create a system that doesn’t have rooms collide