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

How can I do this for more then one part in the same script?

Asked by
DBoi941 57
4 years ago

I have tried a few different ways with no success. This works fine for one part I just don't know the right way to do it for more parts. I am trying to it for ten different parts. Any direction I can be pointed in would be great. Thanks

local part = script.Parent.Part1
local copyPart = part:clone()

while true do
    part.AncestryChanged:wait()
    wait(60 * 2)
    part = copyPart:clone()
    part.Parent = script.Parent
end

1 answer

Log in to vote
0
Answered by 4 years ago

You can use a for statement!

local part = script.Parent:GetChildren() -- change this to the part locations, but keep :GetChildren() because it is needed.
local copypart = part:Clone()

for i, v in pairs(part) do
    v.AncestryChanged:wait()
    wait(120)
    v:Clone() -- i changed this because i thought it might work doing it this way, but change it if needed
    v.Parent = script.Parent
end
end
0
I was trying it with prints in place so I can see whats happening and I noticed its only get one of the ten parts on the first print shouldn't it print all ten part names? local part = script.Parent:GetChildren() for i, v in pairs(part) do print(v.Name, "1") v.AncestryChanged:wait() print(v.Name, "2") wait(5) v:clone() v.Parent = script.Parent end DBoi941 57 — 4y
0
am I crazy or would that spend over 120 second on each part? ForeverBrown 356 — 4y
0
You would just do print(v.Name). And I think it would wait 120 seconds, but I'm just going off this guys script. Tyler090130 619 — 4y
Ad

Answer this question