That’s because that’s technically speaking where the error is. Whitespace doesn’t do anything in Luaᶧ, so this is what the engine sees rather than what you intended:
local Module = {}
function Module.DoSomething()
for Key = 1, 5 do
do
print(Key)
end
end
return Module
--> Missing end, hence the error
Roblox could try to make the parser use whitespace as a hint on what errors to return, but that could be problematic because a lot of Roblox scripts don’t actually indent their stuff correctly.
ᶧExcept in some rare ambiguous syntax cases involving function call expressions.
Roblox thinks there should be three ends instead of two, because of the second do statement. But, when Roblox reaches the end of the module code, it sees there isn’t an end, so it highlights the last line with "Expected end, got <eof>".
Note that we’re correctly attributing the error to failure to close the do statement instead of failing to close the function – this hint is driven by indentation. However this is a heuristic so we don’t actually highlight the mismatch, as the editor doesn’t have this extra context.