Setting a Part's Position Relative to It's Parent

Context: This is a part in a part being used in a viewport frame. The parent is being adjusted to create a good view for the viewportframe, but the child is left behind and can’t be seen (or is incorrectly positioned)

Code:

	local viewportItem = child.Handle:Clone()
	local ogFrame = viewportItem.CFrame
	viewportItem.CFrame = CFrame.new() * viewportItem.ViewportOffset.Value

	for _, otherPart: BasePart in pairs(viewportItem:GetChildren()) do
		if otherPart:IsA("BasePart") == false then
			continue
		end
		otherPart.CFrame = ogFrame:ToObjectSpace(otherPart.CFrame) * viewportItem.CFrame -- * viewportItem.ViewportOffset.Value
	end

Putting parts inside other parts is not the method of moving multiple parts together.

You want to put both parts in a Model and then call Model:PivotTo(CFrame) or Mode.PrimaryPart.CFrame = CFrame

Both methods will move all parts in the model together.

I have no doubt this would work but this isn’t the solution I was looking for. I want to calculate the position relative to the first part as it is a learning experience and can possibly save time. I am not using a model because the original form was a tool instance which I find excessive to create a model with automated pivot.

I’m not at my computer now so I can’t really type.

But if you want to get the offset of one part to another you can use

CFrame:ToObjectSpace()

And CFrame:ToWorldSpace()

To go back and forth between a relative CFrame and world CFrame.

Look it up on the CFrame page in the documentation for more information.

This still placed it in the wrong location.