How do you place a part in front of another part?

How can I place a part in front of another part??

--WORKSPACE: --[[
     -Spawn
     -Part2
     -Baseplate
--]]

local newPart = Instance.new("Part",game.Workspace)
newPart.Anchored = true
newPart.Parent = game.Workspace
newPart.Position = Vector3.new(?,?,?) --Place in front of "Part2" located in the workspace
2 Likes

I think you can do that :

local newPart = Instance.new("Part",game.Workspace)
newPart.Anchored = true
newPart.Parent = game.Workspace
newPart.Position = workspace.Part2.CFrame.Position + Vector3.new(0,0,0) --change one of these to make it in front of him

Have a nice day ! :grin:

1 Like

This is no good. I need the part to ALWAYS be in the front no matter what direction the original part might be facing

1 Like

Ok so :

local newPart = Instance.new("Part",game.Workspace)
newPart.Anchored = true
newPart.Parent = game.Workspace
while wait() do
    newPart.Position = workspace.Part2.CFrame.Position * Vector3.new(0,0,0) --IDK what of these change but it's one
end

Maybe i’m wrong … :sweat_smile:

1 Like

Or :

local newPart = Instance.new("Part",game.Workspace)
newPart.Anchored = true
newPart.Parent = game.Workspace
while wait() do
    newPart.CFrame = workspace.Part2.CFrame * Vector3.new(0,0,0)
end
1 Like

Ehhh, i’d prefer to use no loops. I’m looking for LookVector(something) I believe.

1 Like

Part.Position = Part2.Position + Part2.CFrame.LookVector*5 -- 5 studs in front

1 Like

@FireStrykerAzul’s solution does not account for the orientation of part2.

To consider position as well as orientation, I suggest you use CFrame:ToWorldSpace().

Something like this:

local newPart = Instance.new("Part",game.Workspace)
newPart.Anchored = true
newPart.Parent = game.Workspace
newPart.CFrame = part2.CFrame:ToWorldSpace(CFrame.new(4, 0, 0))

This will keep newPart at a 4 stud offset with respect to position and orientation. If you have any further questions, just message me.

7 Likes

There are 2 ways, first way is to use Attachments.
Position your attachment where you want your part spawn to be.

Now,

local part1 = workspace.Part1
local attach = part1.Attachment

local part2 = Instance.new("Part",workspace)
part2.Name = "Part2"
part2.CFrame = attach.WorldCFrame

Or you can multiply the CFrame with CFrame.

local part1 = workspace.Part1

local part2 = Instance.new("Part",workspace)
part2.Name = "Part2"
part2.CFrame = part1.CFrame*CFrame.new(Vector.new()) -- Change the x,y,z 
1 Like

Thanks. All of these methods can work.