Part of it is organization, but the technical reason for it is that Lua uses do ... end
to define generic 'blocks' of code. while
and for
loops use these inherently, although I'm not sure about the bytecode for repeat
loops and if
statements.
The consequence of this is that do ... end
blocks create a layer of scope:
And any other consequences you can draw from that. It's useful of you want to reuse variable names, although it's more useful to deny access to variables declared in the global scope of a script:
01 | local board = Instance.new( "BillboardGui" , workspace.Player.Head) |
04 | local f = Instance.new( "Frame" , board) |
06 | f.Size = UDim 2. new( 1 , 0 , 1 , 0 ) |
07 | f.BackgroundColor 3 = Color 3. new() |
08 | f.BackgroundTransparency = . 5 |
11 | local txt = Instance.new( "TextLabel" , f) |