Why isn't my code working

This is a segment of my code but it doesn’t seem to work:

if (combatthings == null)
combatthings = GameObject.FindGameObjectsWithTag(“combat”);

foreach (GameObject combats in combatthings)
{
combat comScript = combats.GetComponent();
comScript.attack = false;
}

it is meant to find all objects with the tag “combat” and find a script called combat and then set attack to false in the script

maybe combatThings != null.
add
else
{
debug.log(combatThings != null)
}
to the if statement to check.

maybe this is still null? did you test and see what it contains?

combatthings = GameObject.FindGameObjectsWithTag("combat");

i just tried that but it printed true so the top part of the code isnt the issue

What happens when you do this.

foreach (GameObject combats in combatthings)
{
combat comScript = combats.GetComponent<combat>();
if(combat == null){
Debug.LogError("No combat script was found on gameobject " + combats.name);
}else{
comScript.attack = false;
}
}