I need to use the contents of my table and copy them. They are parts in the workspace, however I used
table.insert()
to add it to the table "unions". Here is my code:
unions = {} function DefineForUnion() -- local things = game.Workspace:GetChildren() for i , v in pairs (things) do if v.className == "UnionOperation" then table.insert(unions,v) wait(2) end end end DefineForUnion() for i, union in pairs (unions) do print("We found the Unions!") if (union.ClassName == "UnionOperation") then local new = union:Clone() new.Size = union.Size * scale new.Parent = game.Workspace new.CFrame = CFrame.new(math.random(1,20),10,math.random(1,20)) print("Copied a union...") wait(2) end
However it does not pass the print "We found the unions".
Any suggestions?
In order to loop through tables, you must use ipairs
.
For example, your code should look something like this:
--Notice the use of "ipairs" here for i, union in ipairs (unions) do print("We found the Unions!") if (union.ClassName == "UnionOperation") then local new = union:Clone() new.Size = union.Size * scale new.Parent = game.Workspace new.CFrame = CFrame.new(math.random(1,20),10,math.random(1,20)) print("Copied a union...") wait(2) end end