Door going inside wall (solved)

local function move()
	local mouseTarget = mouse.Target
	if not mouseTarget then return end

	local hitCFrame = mouseTarget.CFrame
	local normal = hitCFrame.lookVector

	local newPosition = hitCFrame.Position
	newPosition = Vector3.new(mouse.Hit.X, math.floor(hitCFrame.Y), mouse.Hit.Z)
	newPosition = Vector3.new(newPosition.X,mouseTarget.Position.Y + ( (door.PrimaryPart.Size.Y-mouseTarget.Size.Y) /2) ,newPosition.Z)
	
	local doorOrientation = CFrame.Angles(0, math.rad(90), 0)
	local newCFrame = CFrame.new(newPosition) * doorOrientation

	door:PivotTo(newCFrame)
end

how would I just make it always be in position inside the wall?

currently it moves the X/Z coordinates with the mouse and thats why it causes that, whats the alternative?

1 Like