How do I spawn a part in front of another part?

  1. What do you want to achieve?
    See Picture

  2. What is the issue? Part doesn’t move in front of other part.

  3. What solutions have you tried so far? I have screwed around with the CFrame a ton, and I am just not having any luck.

image

local LastPart = script.Parent:FindFirstChild("Part")
local NewPart = LastPart:Clone()
NewPart.Parent = script.Parent
local FirstPartCF = LastPart.CFrame
local FirstPartAngleCF = FirstPartCF-FirstPartCF.Position
NewPart.CFrame = FirstPartAngleCF + Vector3.new(LastPart.CFrame.X + (LastPart.Size.X-(LastPart.Size.Z)), LastPart.CFrame.Y, LastPart.CFrame.Z)

I just want the part to spawn directly in front of the other part with the same rotation.

Can you provide some code? There’s not much I can tell you from what you provided.

local LastPart = script.Parent:FindFirstChild("Part")
local NewPart = LastPart:Clone()
NewPart.Parent = script.Parent
local FirstPartCF = LastPart.CFrame
local FirstPartAngleCF = FirstPartCF-FirstPartCF.Position
NewPart.CFrame = FirstPartAngleCF + Vector3.new(LastPart.CFrame.X + (LastPart.Size.X-(LastPart.Size.Z)), LastPart.CFrame.Y, LastPart.CFrame.Z)

I’m confused, you are using the wrong rotation for your part.

This is the result I got (The orange part is B) :
image

Its not the rotation that is messing up, I was the parts to be in a line with one another while being in the same rotation too. I just want to make a straight line with parts based on the first part’s location essentially.

Figured it out, I had to do

NewPart.CFrame = NewPart.CFrame + LastPart.CFrame.RightVector * -(LastPart.Size.X-(LastPart.Size.Z))
2 Likes

If you’ve found the solution, I have nothing to add. Congrats!
:v:

2 Likes