Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Are there problems with manipulating instances before they're cloned into workspace?

Players can create clones of, for example, tools from a place such as server storage using the :Clone() function.

local Tool = game.ServerStorage.Tool:Clone()

but before they can Parent the tool into workspace, can the player manipulate said item before it can reach the workspace? For example:

local Tool = game.ServerStorage.Tool:Clone()
local Part = Instance.new("Part", Tool")
Part.Size = Vector3.new(1,1,1)
Tool.Parent = workspace

if this is possible, are there problems that could occur and anything I should know before doing stuff like this?

3 comments

0

Don't use the 2nd argument of Instance.new

0

So i just set it to Part.Parent = Tool? I could still manipulate it before it reaches workspace right?

0

Clients cannot access ServerStorage, so the answer is no they can't. Until you parent it into workspace, they won't be able to even see it.

1 answer

✓ Accepted answer

I'm fairly sure you can, because setting properties before the Parent is assigned is common practice. However, only properties like Name and BrickColor are guaranteed to work before the Parent is assigned to the part. Example:

local part = Instance.new("Part") -- Don't use the 2nd parameter
part.Name = "Test"
part.BrickColor = BrickColor.new("Really blue")
part.Size = Vector3.new(1,1,1) -- Not entirely sure if this works, I haven't tested it
part.Position = Vector3.new(math.random(0,256), 1, math.random(0,256)) -- Same for this one
part.Parent = workspace

If this doesn't work, please let me know.

5 comments

0

Perfect! thank you so much! But how come i shouldn't use the 2nd parameter? I've been using it for years and don't see a problem with it?

1

it causes lag in-game

0

I see, performance is key, thank you!

0

@Marmalados Please read over https://devforum.roblox.com/t/psa-dont-use-instance-new-with-parent-argument/30296 , people on this website seem to not understand that there are some usecases where the Parent parameter is fine. Besides, it will help you understand why it is slower.

0

no ^

This discussion is preserved as it was. New answers, comments, and votes are closed.