Like,
do print("idk") end
What is the difference between just using regular code?
do, end is used to create a new scope in a script. This means when you modify a variable or create a local variable inside a do scope the variable will default back to whatever it was before do was called.
myVariable = 5 do local myVariable = 3 print(myVariable) end print(myVariable)
Returns "3" then "5."
do local myVariable = 3 print(myVariable) end print(myVariable)
Returns "3" then "nil."
This can be used to prevent memory leaks for unused variables and temporarily change a variable. Read more here.
Alternatively, you could use do, end to organize your code. For example, place all of your global variables inside a do, end scope so that those lines of code collapse. You'll have an easier time scrolling through your script.
That is not how “do” works. “do” is used for a thing called loops, which you can read about here.
If you’re thinking “do” is supposed to run code or something, it doesn’t do that. The code runs automatically unless it’s in some function or etc.