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

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

Asked by
Uglypoe 557 Donator Moderation Voter
8 years ago

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?

2
It doesn't matter. Efficiency is negligable, and your assumption on the hierarchy requirement is wrong. User#6546 35 — 8y

1 answer

Log in to vote
1
Answered by
hozann 75
8 years ago

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.

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? Uglypoe 557 — 8y
0
Neither. User#6546 35 — 8y
0
^ Wrong answer -_- KingLoneCat 2642 — 8y
0
LOL koolkid8099 705 — 8y
Ad

Answer this question