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

How do I use GetChildren() to move parts in unison?

Asked by 9 years ago

Someone told me to do it like this:

script.Parent.Touched:connect(function()
    script.Parent.Script.Disabled = true
        for index,p in pairs(script.Parent.Parent.Truck:GetChildren()) do
            for i = 1,200 do
                p.Position = p.Position + Vector3.new(.4,0,0)
            end
        wait(.1)    
    end
end)

That didn't work. It teleported the blocks one by one. When I tried this before that, it moved them slowly, but still one by one.

script.Parent.Touched:connect(function()
    script.Parent.Script.Disabled = true
        for index,p in pairs(script.Parent.Parent.Truck:GetChildren()) do
            for i = 1,200 do
                p.Position = p.Position + Vector3.new(.4,0,0)
            wait(.1)    
        end
    end
end)
0
Why not just use "MoveTo()"? Necrorave 560 — 9y
0
How would I do that? Lightdrago 95 — 9y

1 answer

Log in to vote
0
Answered by
Necrorave 560 Moderation Voter
9 years ago

Instead, use MoveTo()

object = game.Workspace.Truck

object:MoveTo(Vector3.new(0, 0, 0)) -- This is how you would use the "MoveTo" method

MoveTo() is helpful when moving an entire model to another place. It would move the model and all of its children at the same time.

Try this:

script.Parent.Touched:connect(function()
    script.Parent.Script.Disabled = true
        script.Parent.Parent.Truck:MoveTo(Vector3.new(0, 0, 0)) --Put down a position you want it to go.
end)

Let me know if it works! :)

EDIT: An example of how you could move in increments.

x = 0
y = 0
z = 0
object = game.Workspace.Part

for i = 0, 100, 1 do
object:MoveTo(Vector3.new(x, y, z))
x = x + .4
end

That is just an example. What you may want to do will take more work. I feel if you fumble around with things, you will get it done :)

Good luck!

0
Is there a way to use MoveTo() to add Vector3.new(.4,0,0) so it moves in increments, and doesn't just teleport? Lightdrago 95 — 9y
0
There is a way, but it can be a bit complex. Create three variables that you increment in a for loop. I will leave an example as to what I mean. One second... Necrorave 560 — 9y
0
Also, to learn more about "MoveTo()". Go here: http://wiki.roblox.com/index.php?title=MoveTo_(Method) Necrorave 560 — 9y
Ad

Answer this question