Wondering if this is undocumented behavior

do return 5 end

Perfectly valid syntax apparently, but can’t find anything in the Lua documentation outlining this behavior.

Being able to return outside a function seems weird.

Outside of Roblox, Lua programs can return a value to other Lua programs just like modules do in Roblox, which is the only place where returning in the main scope makes sense. In Roblox and outside of ModuleScripts, this will just stop the script like returning in a function would, but the returned value won’t go anywhere.

3 Likes

Ahh, so it is documented but pretty pointless.

Thanks.

It’s not pointless. The value is still stored for a chance to be retrieved. I.E returned from the main scope of a loadstring created function.

Ahh, alrighty then.