Give parent to an instance before giving it properties?

Hello developers, I have a question, really what is the correct way to create an instance, my question is this, Suppose I have to create an instance, an example is a part, but first I give it its properties and then the parent, Example:

local Part = Instance.new("Part")
Part.Anchored = true
--And another properties...--
Part.Parent = workspace

and another example would be to create the part and give it a parent first, Example:

local Part = Instance.new("Part")
Part.Parent = workspace
Part.Anchored = true
--And another properties...--
  • Is there a change in these two?
  • Which of these two ways do you use?

Answer here below!

Parent it first, because it wouldn’t make sense to Anchor something that has no place. I use the second one

But technically speaking, they’re both correct.

2 Likes

They are the same thing. I use the first one more, just because I think it’s cleaner. Also, I suggest putting this post in #help-and-feedback:scripting-support

1 Like

I’m not sure if this is still relevant today, however I believe that there is a performance negative for setting the parent first then the properties. (This could just be for the instance.new() parent property though)

3 Likes

It still has some logic now that I see, but anyway I think it works the same in both ways, Thanks for your comment!