Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Is it possible to add code to a script in-game that runs?

Asked by
p0vd 207 Moderation Voter
5 years ago

Title says it all. I would attempt to code this if I could find anything on the internet but I didn't.

0
use https enabled raid6n 2196 — 5y
0
wait nvm read it wrong raid6n 2196 — 5y
0
wait nvm read it wrong raid6n 2196 — 5y
0
wait nvm read it wrong raid6n 2196 — 5y
0
wait nvm read it wrong raid6n 2196 — 5y

2 answers

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

Yes, it's possible. But it's also an easy way to open up your game to server-side exploiting, and shouldn't be done on a production multiplayer game. For something like a single-player scripting tutorial type place, it would be OK.

Two ways you can do this are by enabling loadstring() with ServerScriptService.LoadStringEnabled = true (can be done from the Properties panel via the checkbox), or by linking in a Lua Interpreter ModuleScript. In either case, you can execute arbitrary strings sent from client to server, on the server as Lua code.

Code is executed on the server with loadstring like this:

loadstring(stringOfLuaSourceCode)(arguments)

arguments is optional. loadstring returns your code as a function, so just () will execute it.

Ad
Log in to vote
0
Answered by 5 years ago

No, the only way to access the source of a script is by it's Source property, however that property is locked to command bar and plugin usage. The only other way to dynamically change code at a runtime would be to use loadstring() and change the source of it everytime. However loadstring() does come with it's own set of security risks.

However the better way to do it is by using variables, specifically value objects declared outside of the script (or just simply internally) which can cause the behaviour of a script to change in several ways depending on the implementation.

Answer this question