Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How would I CFrame everything in a Group?

Asked by
Qorm 100
10 years ago
switch=game.Workspace.touchablepartfori
Parts=script.Parent:GetChildren()
debounce=false
function onTouch()
    if debounce==false then
        debounce=true
        wait()
    for i=1,6 do
    Parts.CFrame=CFrame.new(Parts.CFrame.x+1,Parts.CFrame.y,Parts.CFrame.z)
    wait(0.01)
end end end
switch.Touched:connect(onTouch)

Trying to make it so when you touch the button "touchablepartfori", it moves all the parts in the group. How would I be able to do this?

0
Can you rewrite what you said so it make a bit sense. UserOnly20Characters 890 — 10y
0
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. Redbullusa 1580 — 10y
0
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. Redbullusa 1580 — 10y

1 answer

Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
10 years ago

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))
-- Moves the Model's PrimaryPart to (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))
-- Moves the Model up by 1.
  • 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))
-- Moves the Model's PrimaryPart to (0,1,0). If there's something obstructing that area, then the part will go up directly on the y-axis until there's nothing in the way (built-in collision check).

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)

-- NOTE: Example Script

I've tested it and it works. You can see a sample model of it here.

Ad

Answer this question