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

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

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)

2 comments

0

Why not just use "MoveTo()"?

0

How would I do that?

1 answer

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!

3 comments

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?

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...

0

Also, to learn more about "MoveTo()". Go here: http://wiki.roblox.com/index.php?title=MoveTo_(Method)

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