Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

When cloning models and parts, should I set the CFrame after or before parenting them?

Asked by 6 years ago

I recently read several posts on how one should not set the parent of an Instance in the second argument of Instance.new like so:

local part = Instance.new("Part", game.Workspace)

and was wondering: Do I need to set the CFrame of a model/part before parenting it to the workspace(note: the CFrame unable to be determined until the model/part is cloned.)? Is that even possible? Here is an example:

local serverStorage = game:GetService("ServerStorage")
local cloneablePartClone = serverStorage.CloneablePart:Clone()
cloneablePartClone.Parent = game.Workspace
cloneablePartClone.CFrame = CFrame.new() -- whatever you get the point

Hope you guys can help. Thanks!

0
Always set the parent last. It will know where to go to. User#19524 175 — 6y

1 answer

Log in to vote
3
Answered by
chomboghai 2044 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

You should set the CFrame before you parent the object to workspace.

The reason for this - and why you should not use the Instance.new with the parent argument, is because when you parent the part to workspace, the part, and any changes made to it must render in the game. It takes a lot more time to make changes and render accordingly rather than to just make changes. If the parent of the part is nil, then the changes can be made in extremely little time because there is no rendering involved when the part is not in the workspace.

Therefore, you should make sure you set the parent of the part to workspace at the very end to reduce the time it takes to make changes to the part.

0
Agreed. User#19524 175 — 6y
0
Thanks! User#21908 42 — 6y
Ad

Answer this question