"Out of local registers when trying to allocate ...: exceeded limit 200"

Today, after months of work and thousands of lines of code, I ran into this error for the first time:

Players.rogeriodec_games.PlayerGui.LocalScript:2055: Out of local registers when trying to allocate MyFunction: exceeded limit 200

Doing a little research, I realized that it is intentional:

Then I realized that there is a limit to variables (and functions) declared as local.
This is apparently justifiable (at least that’s what the article above shows).
I can fix this error easily by simply removing the term local in front of the declaration of functions or variables.
So local MyFunction() becomes just MyFunction() (or MyVariable)…

However, from the beginning, I was advised to use local in front of variable and function declarations, not only for the sake of scope but mainly for performance.

So I ask: if I can easily “get around” this error by simply removing local from the front of statements, what do I lose by removing local from the front of functions and variables?

1 Like

Whether you lose something when you remove local is up to your code and what the functions hold and do, it’s related to scopes. You can see here: Scope | Roblox Creator Documentation
I think it’s self explanatory what to remove and what-not after you know when to use it and when not to.

1 Like

if you make a variable without local, it will be global and can be accessed with getfenv, _G etc. By another script.

What I recommend now
make them into tables, one local table handles the variables.

local tableofvariables = {
variable = "amogus",
mongus = "mango",
--even tables!
list = {"lol"}
}

print(tableofvariables.mongus) -- "mango"
1 Like

My variable is still getting the same error. It was local to begin with.

Just remove the “local” part before it. For example: “Local bingus = wingus” would be “bingus = wingus”. I ran in to the same problem as you, I had a lot of code. I just removed the local part and it worked fine. Also, because it’s a global variable instead of a local variable, if you have other server sided scripts you can use it without having to define it again. I think. I don’t have a lot of knowledge with global variables.

1 Like

It is true that a local variable is better when it comes to performance, but the difference isn’t that big. If you have some local variables, like settings, I recommend you make a moduleScript for that. Not only you can get some spare local variables, but the customization of your settings will be easier in the future.
Anyway, I wouldn’t really worry about global variables, but if you want to avoid some, maybe use value-instances, or find and replace all variable names with the specific value of some variables.
Edit: Didn’t see the original post was made almost 2 years ago