Stupid question - but wondering if it's any more optimal or it just looks prettier.
Like would
local debris = game:GetService("Debris") for i=1, 10 do local d = Instance.new("Part") d.Parent = game.Workspace debris:AddItem(d, 2) end
Be more efficient than
for i=1, 10 do local d = Instance.new("Part") d.Parent = game.Workspace game:GetService("Debris"):AddItem(d, 2) end
It would be more efficient to use the first as it means that GetService is only called once rather than 10 times. If you wanted it even more efficient, you could do this:
local debris = game:GetService("Debris") local addItem = debris.AddItem for i=1, 10 do local d = Instance.new("Part") d.Parent = game.Workspace addItem(debris, d, 2) end
But you really shouldn't worry about performance unless it's a big issue e.g. running a loop a very large number of times. Do whatever looks neater.