Using Instance.new("Object", parent) bad?

Found this old post, has this been fixed? Or should I avoid this?

1 Like

NO NO NO NO NO STOP RIGHT THERE.

dont start using Instance.new(“Highlight”).Parent = workspace it’s goofy and stupid practice to ignore it!
firstof all it causes your performance to drop (stonks) and when you use Instance.new(“Highlight”, workspace) it’s much better because it saves up more time.

I’m doing this: local mem3 = Instance.new("StringValue", newPartyEntry)

This is fine? Or no?

Hi, I wouldn’t suggest using either. Why?

If you for example create a part, you would want to change the properties of it, before parenting it elsewhere.

local NewPart = Instance.new("Part")
NewPart.Name = "TestPart"
NewPart.Size = Vector3.new(1,1,1)
NewPart.Material = Enum.Material.Neon
NewPart.Position = Vector3.new(0,10,0)
NewPart.Parent = workspace
14 Likes

I personally like creating variables for new instances and setting properties before parenting.

1 Like

Exactly, I don’t know why anyone would create an instance just to parent to workspace and not create a variable.

No, just set the parent after you’ve already defined the variable.

That’s bad practice though. Using Instance.new(“Highlight”,workspace) is better while Instance.new(“Highlight”).Parent = workspace wastes more time.Plus it’s a better way soo

Setting parent as the last thing for a new instance is the better choice. You wouldn’t want the object to be present ingame, before setting the properties correctly first.

2 Likes

Sure. Or just use a.Parent. (i feel like im gonna get bombed with replies)

Explain how it’s a bad practice? Also just because it’s more lines to write does not mean it’s inferior. A perfect example is math.sqrt().

Instance.new("").Parent = workspace or Instance.new("",workspace)
  • Parent tech
  • the (“thing”,parent)
  • Both

0 voters

again my second reply so devforum dosen’t bomb me with their mods being crazy taking down my post.

just use both.they do the exact same thing (now plz stop bombing me with replies)

1 Like

Why are you creating a poll? The OP could have just done that. Honesty you are making things more complicated.

For the most part, this is fine. Your simply instancing a stringvalue and parenting it, no property modifications.

The main problem from the thread is quick creation of many instances where you do work on modifying the properties, where once parenting the object, replication and tied event calculations will happen on that object whenever you set it’s properties, which will result in more work.

It depends on the instance your creating/amount/frequency of creation really,. A basepart has a trifold amount more properties/method’s than a valuebase. So Using;

local stringVal = Instance.new("StringValue", workspace)
stringVal.Value = "jbafkyugbayd"
stringVal.Parent = game.ServerStorage

In comparison to setting size’s/cframe’s of parts has way less work for replication.

1 Like

this is not “place for devs to force and make dev’s more sad and force the op to do this” forum. i am not making things more complicated, i think everyone is. Why are you gonna force someone to get off this forum?

i am this close to quitting the forum :sad:

1 Like

Plus you cant change someones opinion fast

TLDR; Define the new instance with a variable, set properties (if needed), and then parent.

1 extra line for parenting will not impact anything to my knowledge.

Yea but I can still do that, it’s more about saving a slight bit of time. I’m just wondering is there performance issues with that?

If you’re asking only if there is a performance difference, yea parenting last is best for that. There is a few specific cases, where you do not need to change properties of a new instance, these cases you can parent it right away with Instance.new(“Object”,parent)

Personally I think the “saving time” argument is a bit thin. Compared to the amount of time you spend developing a proper game as a whole. :slight_smile:

Yea but at the same time, the argument of how much time spending a proper game means you cut corners when it makes sense :wink:

I mean this does save time even minor as it may be.