Stupid question - but wondering if it's any more optimal or it just looks prettier.
Like would
1 | local debris = game:GetService( "Debris" ) |
2 |
3 | for i = 1 , 10 do |
4 | local d = Instance.new( "Part" ) |
5 | d.Parent = game.Workspace |
6 | debris:AddItem(d, 2 ) |
7 | end |
Be more efficient than
1 | for i = 1 , 10 do |
2 | local d = Instance.new( "Part" ) |
3 | d.Parent = game.Workspace |
4 | game:GetService( "Debris" ):AddItem(d, 2 ) |
5 | 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:
1 | local debris = game:GetService( "Debris" ) |
2 | local addItem = debris.AddItem |
3 |
4 | for i = 1 , 10 do |
5 | local d = Instance.new( "Part" ) |
6 | d.Parent = game.Workspace |
7 | addItem(debris, d, 2 ) |
8 | 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.