If statement doesn't go through when both arguments are met

hi all ! I have an if statement checking to see if an attribute is the same as a part in a table, and it lines up, but it never fires the if statement.

local signalCode = {
	Red = "1",
	Yellow = "2",
	Green = "3"
}

for i, signal in pairs(Signals) do
    for name, code in pairs(signalCode) do
	    print(code, signal:GetAttribute("Aspect"))
	    if signal:GetAttribute("Aspect") == code then
	    	print("hi") -- never prints
		    signalModule.set[name](signal)
	    end
    end
end

image

can anyone help me see if I’ve missed anything ? thanks !

try changing the if statement to this

if tonumber(signal:GetAttribute("Aspect")) == code then
	print("hi") -- never prints
	signalModule.set[name](signal)
end

still doesn’t go through sadly

try wrapping code inside the tonumber() as well.

Still isn’t going through with code in tonumber

okay try removing both the tonumbers and put the aspect atribute inside a tostring

that worked ! thank you very much

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.