Little help needed!

Does anyone know why my code isn’t printing true

local Colors = {
	"Blue",
	"Red",
	"Green"
}

local Frames = script.Parent.Frames

for _,Frame in pairs(Frames:GetChildren()) do
	if Frame.Name == Colors then
		print(True)
	end
end

I know it’s clearly because I’m just comparing the frame name
to a table, but how do I make it to where it compares the frame
name to one of the names inside the table?

4 Likes

Right now you’re checking if the name equals the entire array, you want to use table.find() to compare and check whether the iterated frame name exists in the Colors table.

local Colors = {
	"Blue",
	"Red",
	"Green"
}

local Frames = script.Parent.Frames

for _, Frame in ipairs(Frames:GetChildren()) do
	if table.find(Colors, Frame.Name) then
		print(True)
	end
end
1 Like

nevermind i thought you need to return true if there is a name in the array

Do you need to choose a special color or do you need to check if color exists in array?

You can just use table.find.

local Colors = {
	"Blue",
	"Red",
	"Green"
}

local Frames = script.Parent.Frames

for _,Frame in pairs(Frames:GetChildren()) do
	if table.find(Colors, Frame.Name) then
		print(True)
	end
end
3 Likes

Thank you all for the replies!

2 Likes

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