debug.getstack hands you those slots for one function on the call chain.
level chooses which function: 1 is the one that called debug.getstack. 2 is the function that called that one, and so on up the chain.
index chooses one slot. Leave it out to get the whole set back as a table.
Slots are not only the variables you named. The Luau compiler adds its own values too, so slot 1 is not always your first variable.
Most commonly used while reversing a game script. You hook a function, then read the caller’s slots to see the values it was about to pass in before the real call runs.
Parameters
Returns
any | {any} - the shape depends on whether you pass index.
A slot that has no value throws an error. It does not come back as
nil.
Aliases
getstack
Example
Read a function’s whole frame.peek is called from run, so level 2 is run - its locals are still live while peek runs.