Hey guys. I’d like to know how I could switch the position of parts using a for loop. For example, let’s say I want PartA to teleport to Vector3.new(1, 1, 1), PartB to Vector3.new(0, 2.5, 0), and PartC to Vector3.new(0, 0, 7). How would I attempt to do this?
local Position1 = Vector3.new(1, 1, 1)
local Position2 = Vector3.new(0, 2.5, 0)
local Position3 = Vector3.new(0, 0, 7)
for i, v in pairs(game.Workspace.PartsContainer:GetChildren()) do
v.Position = Position1
-- If I add Position2 or Position3 here, Position1 will be overridden by either of the two.
-- How can I prevent the override, but make sure that all parts won't be placed in the same position?
end
local Positions = {
Vector3.new(1, 1, 1),
Vector3.new(0, 2.5, 0),
Vector3.new(0, 0, 7)
}
for i, v in ipairs(game.Workspace.PartsContainer:GetChildren()) do
v.Position = Positions[i % #Positions]
end
Thanks! This worked! I do have a question though. Do you have an idea of why one of the parts don’t move? I’ve re-tested it multiple times, but only two out of the three parts move.
ooh heck, that’s my bad just slightly adjust the script:
local Positions = {
Vector3.new(1, 1, 1),
Vector3.new(0, 2.5, 0),
Vector3.new(0, 0, 7)
}
for i, v in ipairs(game.Workspace.PartsContainer:GetChildren()) do
v.Position = Positions[(i - 1) % #Positions + 1]
end