Alternatives for GetChildren() in variables

I am trying to make a movement script that moves multiple parts in one model.

Since for whatever reason you can’t move model CFrames (even though they contain them), I am trying to use other ways to move the model’s children instead, however,
I can’t seem to work out how to group them together so I don’t have to go through 100 functions and rename each part to the correct variable.

So, is there any way for me to somehow assign them all to one variable, or do I just have to sit down for 30 minutes and change this script?

use the model:PivotTo() function that should do it

I wouldn’t know how to work that into the script as it’s a

for i = 1,20 do
s.CFrame = s.CFrame + Vector3.new(-0.1,0.1,0)

type of script, and I have little scripting experience.

Besides, I’m pretty sure that the pivot will only move the centre point, and not the actual children themselves.

local model = -- your model reference

local children = {}  -- table to store references to the children

-- Get the children of the model and store them in the table
for _, child in ipairs(model:GetChildren()) do
    table.insert(children, child)
end

-- Now you can access the children using the table
for _, child in ipairs(children) do
    -- Perform operations on each child
    child.Position = Vector3.new(0, 0, 0)  -- Example: Set the position to (0, 0, 0)
end

You could try making a new part inside of the model and setting it as the primary part. Then you can weld all of the parts that you want to move, to the primary part. This will allow you to move all of the parts just by changing the CFrame of the primary part.

It’s a CFrame movement script (it uses frames, which is why it’s called CFrame) so that would not work, I already tried that a few weeks ago for another script too :frowning:

for i = 1,20 do
s:PivotTo(s.PrimaryPart.CFrame * CFrame.new(-.1,.1,0)
end

instead of s.CFrame do s:PivotTo(s.pivotcframethingiforgotthename * CFrame.new(-0.1,0.1,0)) nvm they got it

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.