Code running if statement that isn't supposed to run

Hi all,
I’m running into an issue where an if statement that isn’t supposed to run still runs. To put, I created an instance of a model that has a name, and if its name is “End”, then the if statements aren’t supposed to run, however, it still does and returns the error shown in the picture below along with copy.Name printed, which can clearly be seen as “End”, even though the code was told explicitly that if copy.Name was “End”, it shouldn’t have ran. Any help with this would be greatly appreciated, as I don’t know what could be causing this.

if target == "Front" and copy.Name ~= "End" then
			generatePart(copy.Connectors.Front.Position, length + 1, false, rotation)
			print(copy.Name)
			copy.Connectors.Front.depth = copy.Connectors.Front.depth + 1
			
		elseif target == "Left" and copy.Name ~= "End" then
			generatePart(copy.Connectors.Left.Position, length + 1, false, rotation + 90)
			print(copy.Name)
			copy.Connectors.Left.depth = copy.Connectors.Left.depth + 1
			
		elseif target == "Right" and copy.Name ~= "End" then
			generatePart(copy.Connectors.Right.Position, length + 1, false, rotation + 270)	
			print(copy.Name)
			copy.Connectors.Right.depth = copy.Connectors.Right.depth + 1
			
		end

What does change copy.Name? Try doing print(#copy.Name) to make sure there’s only 3 characters in the string.

Just tried it out, and it appears that there are only three characters in the string.

I also need to mention that commenting out certain lines within the code magically makes it work again, but I’m not sure why this happens, as whatever I change inside the if statement shouldn’t affect whether it runs or not.

if target == "Front" and copy.Name ~= "End" then
		generatePart(copy.Connectors.Front.Position, length + 1, false, rotation)
		print(copy.Name)
		--copy.Connectors.Front.depth = copy.Connectors.Front.depth + 1
			
elseif target == "Left" and copy.Name ~= "End" then
		generatePart(copy.Connectors.Left.Position, length + 1, false, rotation + 90)
		print(copy.Name)
		--copy.Connectors.Left.depth = copy.Connectors.Left.depth + 1
			
elseif target == "Right" and copy.Name ~= "End" then
		generatePart(copy.Connectors.Right.Position, length + 1, false, rotation + 270)	
		print(copy.Name)
		--copy.Connectors.Right.depth = copy.Connectors.Right.depth + 1
			
end

image