Use either the :TranslateBy() method (Vector3), the :SetPrimaryPartCFrame() method (CFrame), or the :MoveTo() method (Vector3), because they're easier than getting the children of the model and offset them.
The difference between these three methods is that:
- SetPrimaryPartCFrame requires a PrimaryPart assigned to the model, can overlap other objects, and its arguments will position the model to the given point.
game.Workspace.Model:SetPrimaryPartCFrame(CFrame.new(0,1,0))
- TranslateBy does not require a PrimaryPart assigned to the model, can overlap other objects, and its arguments will offset the model.
game.Workspace.Model:TranslateBy(Vector3.new(0,1,0))
- MoveTo requires a PrimaryPart assigned to the model, can not overlap other objects, and its arguments will position the model to the given point.
game.Workspace.Model:MoveTo(Vector3.new(0,1,0))
Or if you want to use the 'GetChildren' method and a 'for' loop, you can set the CFrame of all of the children in a given model.
There's one discrepancy you must note: All parts must face in the same direction.
script.Parent.Touched:connect(function ()
local Bricks = script.Parent.Parent:GetChildren()
for i = 1, #Bricks do
if Bricks[i]:IsA("BasePart") then
Bricks[i].CFrame = Bricks[i].CFrame * CFrame.new(1,0,0)
end
end
end)
I've tested it and it works. You can see a sample model of it here.
3 comments
Can you rewrite what you said so it make a bit sense.
On top of the text box when writing/editing a post, there's a handy tool called a "Code block." Click on the blue insignia next to the 'C'. Two sets of squiggly lines should appear. Please enter your code in between them.
I've updated my answer if you want to use the :GetChildren() method and a 'for' loop. But I recommend using other methods I've mentioned.