How to use Studio's command bar to print values of the current script while debugging?

During debug, I want to print the values of some variables that are set while the script is running.
For example, the script has a variable “MyVar”.
However, if I write print(MyVar) in the command bar, I get nil.
How to do that?

You need to write the print statements in the actual script itself.

What you are referring to is called print debugging.

Oh, you see. You have to call it in the same script the value is specified in. Witch, variables can’t do unless you specify it in the command bar. E.g. local value = game.workspace.Value.Value print(value)

Also be aware that the print function takes considerable time to run, and can slow down your script a surprising amount if you leave statements inside of long loops or RunService events. Make sure to clean up when the script is finished and only leave in print statements where they’re neccessary and helpful to you.

I know I can use print inside the script, this is what I always do.
But sometimes you want to query other variable values, without having to interrupt the script, create a print inside the script, run the script, and go through all the processes again.
I can also use “My Watches” in the “Watch” window, however, this window has bugs as I have already reported here:

So, to overcome this bug, I thought that there would be some way to use print inside the command bar to query current script variables, but apparently, there is no way.

1 Like

The only way I can think of would be to store your variables in value objects, and use the console to read those.

Currently the only way to watch upvalues is to make them global. According to zeuxcg this is intended so it would need to be a feature request (which I can’t create).

1 Like