Moving eye welded to a door

I’m making a eye that follows the character. The eye is connected to a door using a WeldConstraint. However, when the eye moves to follow the character, the door also moves, which is not desired. I want only the eye orientation to change, without affecting the position of the door.

Eye Script

function findTorso(pos)
	local torso = nil
	local dist = 100000
	local child = workspace:children()
	for i=1, #child do
		if child[i].className == "Model" then
			local h = child[i]:findFirstChild("Humanoid")
			if h ~= nil then
				local check = child[i]:findFirstChild("Head")
				if check ~= nil then
					if (check.Position - pos).magnitude < dist then
						torso = check
						dist = (check.Position - pos).magnitude
					end
				end
			end
		end
	end
	return torso
end

game:GetService("RunService").Stepped:Connect(function()
	local torso = findTorso(script.Parent.Position)
	if torso ~= nil then
		script.Parent.CFrame = CFrame.new(script.Parent.Position, torso.Position)
	end
end)

Your script moves the eye based on the character’s head position so it affects the connected door. My recommendation for this is using only the character’s head rotation to orient the eye without changing the position

For this, you will have to change the CFrame settings inside the weld instead of directly changing the CFrame’s of the eye.

You need to be using either a Motor6D or a regular Weld. Weld Constraints will move no matter what. If you switch to either of the two I mentioned, you can just have a offset so it will be in the right position, and then modify it on the Stepped function to look at you. To only change the position, take the new weld’s positional offset from either the C0 (Part0) or C1 (Part1) depending on how you have it. Now do a CFrame.new(--[[position goes here]])*CFrame.Angles(make the angle and convert each of the X, Y and Z angles to radians). Hope this helps

thank you, i’ve been hours trying to solve this :slight_smile:

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