How to write one command that prints the value of every variable in a script?

How do I write a command like:
instead of having to write:
I have a script with 40+ variables and It would save a lot of time debugging if I didn’t have to write an individual print command for every variable.

This would be possible with the debug library with functions such as debug.getlocal() & debug.getupvalue() but unfortunately due to security reasons the debug library’s capabilities are limited in Roblox (most of its functions are redacted).

Instead, you can use the getfenv() global function which is exclusive to Roblox.

It works similar to “_ENV” in standard Lua.

Whilst this answer is correct in some ways, I would just like to point out that if you are to use this method in your game you’ll have to remove it before doing any playtesting/ publishing. This is because when you use either getfenv or setfenv your scripts environment is set as impure, leading to the VM to perform dynamic deoptimization.

The downsides are listed but not included to: losing inline caching for table fields, import chaining, index optimizations, fastcall for built ins, table iterator optimizations, table creation optimizations, native vector math, upvalue optimizations, better memory allocation.

If you really want to save time only print variables that are relevant for you or go above and beyond to make a plugin which allows you to see all variables within a given program at once.