Maybe disable 200 local variable limit on local scripts?

I know I’m going to get a bunch of crap for this, but my script simply takes more than 200 local variables. I see no reason to split up my code into modules(I understand it all, and I’m not interested in co-developing), and it seriously is that much scripting. I can’t be too much more efficient without getting unnecessarily complex. What is the real purpose of limiting the local variables to 200? Does roblox lua break past that or something?waterror.png

edit 2019: this is a very old post, I dont agree with it anymore lol. One should be able to use modules and not get anywhere near 200 local variables


You can get by this by making tables of variables whenever possible.

    local vartab = {}
    vartab[1] = 'variable1'
    vartab[2] = 123
    vartab[3] = {'mulah',23,'gulah')
    etc. etc.

    --and then call them like


I know I can just do _={} print(_.variableName) but why must I do that? I don’t get the point of the limit unless it holds roblox back or breaks something.

1 Like

This may be because at that point its useless.

The performance may just as fast using non-local (global?) variables. Think of it like having favorites in your contacts. Once you add 200 favorites there’s no point anymore, it just takes to long to find everyone.


oh. I think it’s a restriction of Lua itself.

That cap is in stock Lua. Either use a bypass as johnnygadget suggested, or try to define as many variables outside the function as possible. Things like non-scope dependent constants, counters, etc.

(also, in response to the title, 200 upvalue limit is only for functions, not to any specific scope)

If that is actually the case, then fair enough. It’s not like I have variables that could totally work inside functions, as global locals. I really do have that much stuff in my main client script.

Another idea:

local This = true
	local That = false
	local Two = 2

	local Foo = "Bar"
	local This = "That"
	local Bar = "Foo"

	local Lenny = "( ͡° ͜ʖ ͡°)"
	local Happy = ":)"

Using do and end creates a new scope for variables and parts of code, that other parts of the code can’t see, removing the local variable issue.

Also, the reason I would not recommend @johnnygadget’s method is that referencing tables can be costly, mostly in large for or while loops. However, this should only concern you if you are someone like AxisAngle and wants to have the fastest code possible.

Yeah I know. That could lower the count, but damn that would make my code ugly. I’d rather just use one local table before each variable shudder

Yeah, 200 local variables is actually imposed by Lua:

It’s imposed by the bytecode format, probably because they dump it as a char (see

ROBLOX probably could change it, but I doubt there would be any point to it (since it’s not often that people use more than 200 locals and 60 upvalues) so they aren’t likely to change it soon.


I’m really curious to see what you’re doing that needs so many local variables… Could you share some of your code?


Breaking things up is great for readability and organization, regardless of if you plan on sharing your code or not. It’s nice to come back to your code in a year’s time and still make quick sense of it.

Obviously this is your call, but I’m really interested in knowing what you’re making!

1 Like

I guess I don’t need this many local variables, but it saves time to type out a variable than an object path that is 3 or 4 objects long. I also make my functions local. I have a ton of tiny features that make this game extra better than the original copy, and tiny bits of coding add up.

It’s more that each VM instruction is 32 bits [llimits.h], they use 6 for the opcode and need three arguments, so that’s 26 bits between 3 arguments [lopcodes.h] and arguments need to be able to refer to a local by number.

So it’d take a lot of effort for ROBLOX to change.


I just gotta know, how on earth have you managed to have over 200 local variables?
You have to be doing something wrong 0.o

1 Like

I’m not doing anything wrong except(perhaps in your opinion) not using modulescripts. I don’t use them because I haven’t needed to. Everything is clean and non-repetitive. There is such a thing as a game requiring lots of code - this is one.

If you need any help with handling cross-environment module code, I’m your guy.

I just don’t see the point of modulescripts client-side(for this game). I can find everything pretty good. It would be nice server-side, but nearly all functions use variables in the main scope, and I don’t know how to work with that without getting hacky.

Just do what assembly programmers do. They have a limited number of registers (which are like global variables) and if they need more than 32 (or 64, or however many the architecture supports) they push unused values into memory (which in lua would probably be represented by a big table in which things get added to and removed from the back).Then, when you need those values again, you just pop them off the “stack” of memory and into your variables.

Yeah I may just have to have a local table to hold all my variables. I can and have removed a few local variables that weren’t truly necessary, but I am going to inevitably reach the limit again.