Assigning to command bar variables inconsistent

Recreation Steps & Actual Behaviour:

  1. Go into Roblox Studio
  2. In the command bar, type the commands as seen in this image (which was run while the game was “Running” but the same thing happens even if it isn’t running):

Text version:

> a = {}
> function b() print(a) end
> a = nil
> b()
table: 0x513f0647d4fecc0d  {}

> a = {} function b() print(a) end
> a = nil
> b()

(The only difference between the two code blocks is that you end up pressing Enter four times in the first and three times in the second.)

Expected Behaviour:
Assigning to a should overwrite the value that b sees regardless of which line b is defined.


  • Exiting all Betas and restarting Studio did not change the result
  • I’m on Windows 10, Roblox Studio Version 0.476.5.421371 (64bit)
  • Disabling plugins made no difference
  • Disabling these properties made no difference (I didn’t test all of them): Debugger Enabled and Command bar operates on local state at breakpoint

Thanks for the report! We’ve filed a ticket to our internal database and we’ll follow up when we have an update for you.

1 Like

It appears that the assignment isn’t wrong, but that there is some optimization which prevents the actual value of the global variable from being read. Whenever the global variable has an initial value, is never assigned to within that chunk of code, and some other conditions with environments the accesses to the global variable get optimized away. This optimization doesn’t consider multiple chunks which start with the same environment, where some chunks may execute before compiling other chunks.


Using getfenv stops these optimizations, so the examples using getfenv work fine.
Doing any assignment on the global variable also prevents optimization, so this works fine.
The indirect assignment isn’t detected, so this outputs the incorrect value.

1 Like