Max lua stack size reached

I’m encountering the “Max lua stack size reached” error in Roblox Studio. I’m not sure what is causing the issue.

I’ve checked my code, and there don’t seem to be any infinite loops or obvious recursive calls, but I still can’t resolve the error. Does anyone have experience with this issue and know what the possible causes might be or how I can fix it?

Any suggestions would be greatly appreciated!

Thanks in advance!

2 Likes

Are you doing anything like modifying a Value inside of its .Changed event?
Otherwise we’ll probably need to see the code where the error is coming from.

1 Like

The stack is mainly used to store local variables, so check for something that could be declaring an unintended amount. That’s about all I can tell without seeing your code.

1 Like

No i don’t use .Changed events and the error comes from when im trying to create a snaphot in LuauHeap Client

1 Like

The problem is that I don’t have one script, but many, so I don’t know where the error comes from.

1 Like

Adding onto this, it could also be function calls (non-fastcall, more than 3 arguments), so you could also try looking for a function call with a large amount of arguments.

1 Like

No, I don’t have any functions with more than 3 arguments.

1 Like

Well the error you’re getting is pretty ambiguous, I’m not really sure how you could approach it either. Might even be an engine bug, so unless you get a solution here I’d suggest reporting it.

1 Like

Ah, so not during normal gameplay but just when trying to take the heap snapshot?

If that’s the case it is possible it could be an engine bug. It does sound like they’ve had issues in the past. LuaHeap Server Snapshots Crashing Server

1 Like

I did my research, and found out that it happens when you use too many variables. What is the biggest script you have on your game? Does it have lots of variables?

1 Like

Yes my scripts have a lot of variables

2 Likes

Well, can you temporarily remove some of them, just to see if this error will disappear?

1 Like

Uhm, if i remove some variables it will ofc error something

1 Like

Yeah, but it won’t pop the error “Max lua stack size reached”. I know it will pop other ones, but it is only an experience that you could easily revert back to normal

i have just tried removing the 90% of the variables but it still pops the error “Max lua stack size reached”.

1 Like

Oh, then I don’t know what the issue is.

Do you think we can see the script?

As I said, I don’t know which script is causing this issue.

Go around disabling scripts and see if it changes anything

I disabled all the scripts in the game, but it still gives the error.