I think we should have a method called :Duplicate(), I find myself copying a asset only to keep it in the same hierarchy.
To me this would be useful.
It would have the same functionality as CTRL+D (Duplicate Command) in Studio. And preferably also set the Parent property last internally, for optimization reasons.
So the same as :Clone() but with the option to parent the new instance to the same hierarchy?
I don’t see why it should be a whole new method, though. And it can be done in 2 lines of code, or 1 if you don’t care about saving it as a variable.
“Duplicate” would have the same problem regardless. @Foilio most likely you aren’t just going to stop at object:Clone().Parent=object.Parent; you’ll probably be changing something about the clone.
You wouldn’t. The parent obviously would be set after all of the other properties. The problem would be with changing the properties of the clone after it’s been parented. You’re probably not going to just duplicate an object inside of something and not change anything about it.
But that’s the entire point of the proposal. If you’re going to be changing properties then you might as well clone it and change the parent while you’re at it. I want to know what’s the use case for only changing the Parent property.
Isn’t only changing the parent property exactly what this Duplicate would do differently? Instance.Duplicate=function(Object)Object:Clone().Parent=Object.Parent end
So just giving Clone a Parent parameter would achieve the same thing, wouldn’t it?
Use-case wise, if I want to duplicate a part, I probably want to move it somewhere else afterwards rather than just having a part that’s exactly the same as another part in the exact same position. I would be changing this property after its parent is set, which has the same performance implications as the parent parameter in Instance.new, which in the same way would have the same performance implications as a parent parameter on Clone. The only difference between Instance:Duplicate() and Instance:Clone(Parent) is that you can choose the parent and there doesn’t have to be a new method created.