For some reason the when the script below runs, my dropper model and my door part switch places. I can't figure out why for the life of me. The door shouldn't even be able to get or use the dropper position. The objects I'm cloning are in the same exact hierarchy as the original plot, so I don't see that being a reason. Any insight as to how this works would be greatly appreciated.
game.Players.PlayerRemoving:connect(function(player) if(player == Owner) then local doorClone = game.workspace.cloneParts.GetOwner:Clone() doorClone.Parent = script.Parent.Parent.Parent for index, child in ipairs(script.Parent.Parent:GetChildren()) do childOrig[index] = child if (childOrig[index]:IsA("Part")) then childOrigPos[index] = childOrig[index].Position elseif (childOrig[index]:IsA("Model")) then childOrigPos[index] = childOrig[index]:GetModelCFrame().p end childOrig[index]:Destroy() end for index, cloned in ipairs(doorClone:GetChildren()) do childClone[index] = cloned if (childClone[index]:IsA("Part")) then childClone[index].Position = childOrigPos[index] elseif (childClone[index]:IsA("Model")) then childClone[index]:MoveTo(childOrigPos[index]) end end GetOwner:Destroy() print('cloned') end end)
:GetChildren()
returns objects in no particular order. You should never use the index
that you get from iterating over it.
Instead, use the child
as the index for the original position
It's not idiomatic to use ()
in conditions in an if
.
You shouldn't use childOrig[index]
to refer to child
You shouldn't use childClone[index]
to refer to cloned
You're trying to compare objects between two different models. That's difficult to manage correctly (what if the models were completely different models?) Your code can't easily enforce that they're the same.
Really, you should copy from the representation that you created; by iterating over childOrig
and creating new children and putting into a model (rather than cloning a model and trying to find the corresponding things in the map)