How Can Written Code from a TextBox Be Inserted into a Script to Run?

Hello fellow developers,

Basically, what I am asking is if there is text written in a TextBox, and that text is syntax for Lua, can that text be inserted in a script to run?

For example, if a player types this code in a TextBox, is there a way where this code can be copied and pasted into one the scripts shown below while the game is running? So, when they click the “RUN CODE” button, the code they have typed actually runs. Is this possible?

Right now, I am just curious and would like to know if this is possible. But, if we are able to do this, then it would be extremely useful for coding games (where the player can type code and actually execute it).

Thank you for reading this.

I’m not sure if it is possible to apply it to already existing scripts, but take a look at the resource below. One of the uses listed for it is running code that the user writes with limited functions to make it more secure.

2 Likes

Yes this is possible! My post linked above uses loadstring to run code. I’ve just added sandboxing on top of it which allows you to make code more secure.

3 Likes