'How to create a Line of parts that always increment on a relative axis?

I’ve sketched this out and have gone over it myself and I don’t know if I’m just being incredibly stupid. But I cannot figure this out.

How could I clone a part and have it offset on its relative x-axis? Like 4 meters down on the same “line”.

For example, Green is the start, but every part would be a clone to the left of its axis.

Try using a Pivot. PivotTo is one function that can perform this.

Pivots are set randomly and are sometimes -primaryPart.Position. I’m not sure how to set it without setting the primary part.

local function repeatPart(part: BasePart, count: number, distance: number): ()
    for i = 1, count do
        local clone = part:Clone()
        clone.CFrame = part.CFrame + part.CFrame.LookVector * (i * distance)
        clone.Parent = part.Parent -- What if the part is not directly in workspace?
    end
end


You can also use UpVector and RightVector (as well as reverse those vectors for the opposite direction) to clone parts in different directions.

Multiply the original Part’s CFrame by a Vector3. This will return a Vector3 offset in object space by the Vector3.

For example:

local newVector3 = Part.CFrame * Vector3.new(5, 0, 0)

The code above will create a Vector3 relative to the Part’s x-axis.

CORRECTION: CFrame * Vector3 returns a Vector3, not a CFrame. Refer to the solution for an answer that’s more correct.

I’ve already tried this but you cannot multiply CFrame values by Vector Values. Thank you though.
Unable to assign property CFrame. CoordinateFrame expected, got Vector3

Clone.CFrame = Clone.CFrame * Vector3.new(5,0,0)

That’s because CFrame * Vector3 returns a Vector3. Part.CFrame expects a CFrame, but you provided a Vector3 instead. If you want it to return a CFrame, you can multiply the CFrame by another CFrame:

local newCFrame = Part.CFrame * CFrame.new(5, 0, 0)

This will also preserve the orientation.

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