If statement is not read by the code(if statement is nested in RenderStepped function)

I have a code where it checks wither to color a Union green or red, depending its name

The issue is, the If statements are not getting read by the code

I’ve tried rearranging the code alot of types it did not work

My guess was that maybe the code behaves this way because its “nested in a RenderStepped function” it doesn’t have enough time to read the “long” if statement.

heres the if statement:

the error message:

What could be possible solutions I could do?

Is there a way to pause a RenderStepped and resume it again?

In Lua, the logical conjunction operation (and) has higher precedence than the logical disjunction operation (or). The expression a == b or c or d actually doesn’t check if CurrentPlant.Name equals c or d and only checks if it equals to b, this is a common mistake and lead to silent logic errors. So if a ~= b then it evaluates to c or d which in your case, the expression could potentially return "OmphalophloiosS" as CurrentPlant.Name might not equal "Fern" or the other operand in the and operation evaluates to false (oldplantposition ~= 0 is false for example) due to the precedence of these operations.

So in your example, it either returns true or the strings in the right hand side of the or operand, which both gets casted to true in the if statement as the only value that gets casted to the false boolean is false and nil.

You could compare CurrentPlant.Name == to other strings in the other side of the or operand and put parenthesis around the or operands.