Method Instance:Duplicate()

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.

1 Like

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.

1 Like

Well when you say it like that

Agreed:

Object:clone().Parent = ObjectCloned.Parent

1 Like

why not a Parent parameter for Clone?
object:Clone(object.Parent)

4 Likes

PSA: Don't use Instance.new() with parent argument ?

Isn’t that the same thing as this?

1 Like

It doesn’t have to be, why not set the parent at the end internally? If it’s a method argument why not

“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.

No because duplicate would certainly be implemented as a call to Clone and then a Parent set.

Why would you need to clone something and then immediately parent it?

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.

1 Like

Isn’t only changing the parent property exactly what this Duplicate would do differently?
Instance.Duplicate=function(Object)Object:Clone().Parent=Object.Parent end

Yes

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.

I don’t think you understand. I’m not arguing anything. I’m just asking OP what the purpose is.