If then statement doesn't seem to recognize whether if the part is equal to the index value

So I made an if and then statement that checks whether if the part name is equal to the index value then it would do some kind of code. But for some reason, it doesn’t seem to recognize that. Is there any way that you could check if the part name is equal to some value of a variable???

Here is the code if your wondering:

while true do
	local simonPicker = math.random(#simonOrNot)
	local simonPicked = simonOrNot[simonPicker]
	-- print(simonPicked)
	local colourPicking = math.random(#colourPicker)
	local colourPicked = colourPicker[colourPicking]
	local colourIndex = table.find(colourPicker, colourPicked)
	-- print(colourPicked)
	print(colourIndex)
	ColourTiles(gamemodeClone.Tiles)
	if simonPicked == "Simon says go to " then
		for i = 5, 0, -1 do
			status.Value = simonPicked..colourPicked..i
			wait(1)
		end
		for _,Part in ipairs(gamemodeClone.Tiles:GetChildren()) do
			if Part:IsA("Part") then
				if not Part.Name == colourIndex then
					print("not = to colour index")
					for i = 0, 1, 0.0625 do
						Part.Transparency = i
						wait()
					end
					Part.CanCollide = false
				end
			end
		end
		status.Value = simonPicked..colourPicked
		wait(3)
	elseif simonPicked == "Go to " then
		for i = 5, 0, -1 do
			status.Value = simonPicked..colourPicked..i
			wait(1)
		end
		for _,Part in ipairs(gamemodeClone.Tiles:GetChildren()) do
			if Part:IsA("Part") then
				if Part.Name == colourIndex then
					print("part = to colour index")
					for i = 0, 1, 0.0625 do
						Part.Transparency = i
						wait()
					end
					Part.CanCollide = false
				end
			end
		end
		status.Value = simonPicked..colourPicked
		wait(3)
	end
	for _,Part in ipairs(gamemodeClone.Tiles:GetChildren()) do
		if Part:IsA("Part") then
			Part.Transparency = 0 
			Part.CanCollide = true
		end
	end
	wait(3)
end

is the index and the part name a string? if they both arent numbers or both arent strings then they technically are not the same, you could do

if part.Name == tostring(colourIndex) then

also instead of using

if not Part.Name == colourIndex then

you should use the not equal to variable, I had a headache because i did it this way and it didn’t work

do it like this

if Part.Name ~= tostring(colourIndex) then
1 Like