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

Which is better, pre-making a part or defining a part in a script?

For example, say I want to clone a specific part several times in a script. What would be more efficient, to define it all as a variable at the beginning of the script or to actually create the part and place it inside the script?

Defined Part Example:

local Part = Instance.new("Part")
Part.CanCollide = false
Part.Size = Vector3.new(2,2,2)
Part.Transparency = 1

script.Parent.Touched:connect(function()
local newpart = Part:clone()
newpart.Parent = workspace
end)

Pre-Made Part Example:

local Part = script:FindFirstChild("Part")

script.Parent.Touched:connect(function()
local newpart = Part:clone()
newpart.Parent = workspace
end)

I find it confusing because with the defined version, the part doesn't have to physically exist inside the script yet, whereas it does with the pre-made example. Which one would be better to use?

1 comment

2

It doesn't matter. Efficiency is negligable, and your assumption on the hierarchy requirement is wrong.

1 answer

I'd suggest the pre-made part, because it's easier to obtain a part and give it a location and property. It's also a lot more efficient. If you have any further queries let me know.

4 comments

0

Either way is easier for me to do, but I guess my real question is to break it down even more: Which method is more efficient in terms of processing time and such?

0

Neither.

0

^ Wrong answer -_-

0

LOL

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