LookVector acting strange?

I am currently working on a custom modular factory system where it’s purpose is every “tick” it calls the function :TransferItems() now this function is required to check if the next machine has a “inDirection” attachment that has to face the same way as the “outDirection” on the current.

For some reason it gives me wild lookvectors and acts strangely.

image

I can see on the Axis property of them that one of them is -1,0,0 and the other is 1,0,0 but they are facing the same way?

image

image

and the other difference is that when I try to change the Axis to be the same as the current one, it makes the rotation in the Y axis to 180 while making it face the wrong way.

Now I do know that they might be facing a weird way already, but for some reason it worked rotating them 45 when I was making the object checking system to check if the conveyor was infront of the DropoffZone belt

My system works with a FactoryManager that holds all players factories, while scripts can add other machines to it which it runs the :TransferItems() and :ProcessItems() functions.

So in short what im trying to do is check if both lookvectors are the same, but they are supposed to be the same but isn’t.

It could be because attachments have both a CFrame property, as well as a WorldCFrame property.

Could you post some code snippets - but my first though would be to use WorldCFrame rather than CFrame (assuming you are currently using CFrame)

Something like

attachment.WorldCFrame.lookVector

Yes alright, the system I have been working on has individual modulescripts for each machine / belt and one modulescript for the FactoryManager. This code is from the DropoffZone belt modulescript.

-- On creation of this object
function DropoffZone.new(object)
	local self = setmetatable({}, DropoffZone)
	self.object = object
	self.PrimaryPart = object.PrimaryPart
	self.items = {} -- items currently in the drop-off zone
	return self
end
-- inside :transferItems(factoryManager, userId)

-- Check if the DropoffZone has a PrimaryPart
	if not self.PrimaryPart then
		warn("DropoffZone does not have a PrimaryPart")
		return nil
	end
	

	-- Check for a connected machine
	--[[for _, machine in pairs(factoryManager.machines) do
		if machine ~= self and machine.PrimaryPart then
			local endPosition = attachment.WorldPosition + attachment.WorldCFrame.LookVector * 3 -- Assuming 3 units long zone
			
			local machineAttachment = machine.PrimaryPart:FindFirstChild("Attachment")
			if machineAttachment and (machineAttachment.WorldPosition - endPosition).Magnitude <= 1 then
				return machine
			end
		end
	end]]

	-- Check for a connected belt
	for _, belt in pairs(factoryManager.belts) do
		if belt ~= self and belt.PrimaryPart then
			--warn("DEBUG DROPOFFZONE")
			
			--print(belt.object)
			--print(belt.PrimaryPart.Position)
			
			local isCorrectObject = false
			local isAllowed = false
			
			local selfOuts = {}
			local selfIns = {}
			
			local beltOuts = {}
			local beltIns = {}
			
			for _,att in pairs(self.PrimaryPart:GetChildren()) do
				if not att:IsA("Attachment") then
					continue
				end
				
				if att.Name == "inDirection" then
					table.insert(selfIns, att)
				end
				
				if att.Name == "outDirection" then
					table.insert(selfOuts, att)
				end
			end
			
			for _,att in pairs(belt.PrimaryPart:GetChildren()) do
				if not att:IsA("Attachment") then
					continue
				end
				
				if att.Name == "inDirection" then
					table.insert(beltIns, att)
				end
				
				if att.Name == "outDirection" then
					table.insert(beltOuts, att)
				end
			end
			
			if #beltIns == 0 then
				continue
			end
			
			local chosenNum
			local chosenAtt
			
			
			
			if #selfOuts > 1 then
				chosenNum = math.random(1,#selfOuts)
				chosenAtt = selfOuts[chosenNum]
			else
				chosenAtt = selfOuts[1]
			end
			
			if not chosenAtt then
				continue
			end
			
			local endPosition = chosenAtt.WorldPosition + chosenAtt.WorldCFrame.LookVector * 3 -- Assuming 3 units long zone
			
			local chosenInAtt
			
			for i,v in pairs(beltIns) do
				print(v)
				print(v.WorldCFrame.LookVector)
				print(chosenAtt.WorldCFrame.LookVector)
				if v.WorldCFrame.LookVector == chosenAtt.WorldCFrame.LookVector then
					print("is allowed!!")
					chosenInAtt = v
					isAllowed = true
				end
			end
			
			if chosenInAtt == nil then continue end
			
			print(chosenInAtt)
			
			local distance = (chosenInAtt.WorldPosition - endPosition).Magnitude
			
			--print(beltAttachment.WorldCFrame.LookVector)
			
			debugObject(endPosition)
			
			--warn(distance)
			if chosenInAtt and distance <= 1 then
				isCorrectObject = true
				print("IS WITHIN REACH")
				--print(distance)
				return belt
			end
			
			print(isAllowed)
			print(isCorrectObject)
			
			if isAllowed and isCorrectObject then
				warn("IS GOOD!")
				return belt
			end
			--warn("--------------------------")
		end
	end

	return nil

This is quite a complex project for me apologies if its got stuff in it that’s not being used.

It can have both in and out attachments or only one of them depending on the machine / belt

image

Little update to the post, I figured out that it would not cause the issue when I placed it, but the moment I left the game and rejoined and that is when my data loaded back up again.