Execute/Eval Script

Is there a way to evaluate/execute code in lua. So lets say someone types print("hi") in a textBox, the script will now execute that.

Lua does have a method of doing this loadstring().
I have no idea if it’ll work on roblox, but in the Documentation it does exist still: Lua Globals | Roblox Creator Documentation

Now, should you allow this? Probably not.
Someone could easily run malicious code. At the very least you should find a way to verify the code being run.

The thing im doing is making a Promo Code plugin that I want to allow Game Owners to run a custom script when a user uses a promo code. No malicious code can be used.

Okay, just make sure it checks that it is truly the owner that is executing the command.

You will also have to enable loadstring via the LoadStringEnabled property in ServerScriptService. Also I don’t think (not sure) you can loadstring on client (localscript).

I just do loadstring(code) or what?

For example:

loadstring("print('hi!')")()

Has the same effect as:

print('hi!')

PLEASE NOTE: When using loadstring, you will have to use two sets of parenthesis,
This will work:

loadstring("print('test')")()

This will NOT work:

loadstring("print('test')")
1 Like