Selecting All Children And Teleporting Them One By One?

Hello!

I’m basically trying to get all children of a model (All children have the same names) to teleport somewhere. I know how to do that, I just don’t know how to add a delay between each children’s teleportation. How do I do it?

(In this situation, I want the children aka the parts to teleport to the player’s HumanoidRootPart)

2 Likes

just simply add a wait before each cycle ends.

for i loop do
--Code here
wait(.1) -- change the interval
end
1 Like

Yeah but if I use something like this… (Just an example)

for _, v in pairs (game.workspace:GetDescendants())do
   if v.Name == 'Part' then
       v.CFrame= Character.HumanoidRootPart.CFrame
   end
end

I’ll teleport them all at once, which I don’t want. I want to teleport them one by one. How do I do it?

…As i’ve said… Add a wait…

for _, v pairs loop do
--Code
wait(.1)-- change this interval
end
1 Like

Wait how will I select all children? (Sorry, I’ve just never used that before)

for _, v in pairs (game.workspace:GetDescendants())do
   if v.Name == 'Part' then
       v.CFrame= Character.HumanoidRootPart.CFrame
   end

   wait(.1)
end

I’d suggest you start learning scripting, as alot of people aren’t willing to babyfeed code.

3 Likes

ipairs is used for arrays, GetDescendants() returns an array, and ipairs runs faster in this case.
pairs is more used for dictionaries.

Also, if you assign it to a local variable, it will speed it up even more.

Here’s an example:

local Workspace = game:GetService('Workspace')
local GetDescendants = Workspace:GetDescendants()

for _, Inside in ipairs(GetDescendants) do
   if Inside:IsA('BasePart') then
      --- Teleport the parts
      Inside.CFrame = NewCFrame
   end
end
1 Like