Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I CFrame everything in a Group?

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?

3 comments

0

Can you rewrite what you said so it make a bit sense.

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.

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.

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.