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?
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:
game.Workspace.Model:SetPrimaryPartCFrame(CFrame.new(0,1,0)) -- Moves the Model's PrimaryPart to (0,1,0).
game.Workspace.Model:TranslateBy(Vector3.new(0,1,0)) -- Moves the Model up by 1.
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.