|
| 10 Nov 2016 08:19 PM |
I would like to make a script builder game, BUT, where you type the code in a textbox / frame and then when you press a "Run code" button, it makes the code execute, for example if in the code box / frame someone writes: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ game.Players.DaCrazyDev:Kick('Bye!') ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Then it actually kicks me.
Please help, I could also offer a sum of robux! |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2016 08:21 PM |
use a remote event to sent the code to the server then run the code on the server using loadstring with loadstring enabled either that or you can make your own parser from string to lua like khol has done |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2016 08:23 PM |
@Wuner_Wufle
Thanks, but how would I use loadstring?
And how would I make a parser? |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2016 08:25 PM |
as i said you only need a lua parser if you cant use loadstring or do not want to if you don't really care then turn on loadstringenabled and use the loadstring function
loadstring([[print("hello world")]])()
it works like the new 'load' in lua 5.2 but cant load bytecode anymore but strings still work it returns a function which you can run |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2016 08:25 PM |
'Making a parser' isn't necessarily easy, it's not something you want to do for a quick solution.
It requires tokenizing, parsing, and evaluating which isn't easy (and causes somewhat of a delay when benchmarks are done against regular scripting). |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2016 08:29 PM |
@Real_Spooky
I agree, I don't even know what it IS... |
|
|
| Report Abuse |
|
|
| |
|
|
| 10 Nov 2016 08:32 PM |
@Wunder_Wuffle
But wait, how would I make it loadstring the TEXT?
Example:
text = script.Parent.Text
loadstring(text)()
? |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2016 08:35 PM |
| yep thats how, thanks so much lol |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2016 08:39 PM |
make sure to wrap it in a pcall and if you want it to run on the server instead of client you can send the loaded function to a remote event and have a script run it
and why pcall?
print(pcall(loadstring("peieodk('lol')")))
to let you know of script errors and give them a notification of them |
|
|
| Report Abuse |
|
|
| |
|
|
| 10 Nov 2016 08:54 PM |
| how about error() instead of print() tho? |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2016 10:35 PM |
errors in pcall are returned
if it errors the first return will be false, if not, it will be true if it errors, it also returns the error or nil |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2016 10:38 PM |
| Its sad that roblox didnt implement the new lua errors where you can error a table |
|
|
| Report Abuse |
|
|
0x02
|
  |
| Joined: 26 Jun 2013 |
| Total Posts: 83 |
|
|
| 10 Nov 2016 10:39 PM |
| Nobody has brought up that executing code on the server is not the same as executing code on the client. You will have to setup some security to prevent people from being able to easily break the entire script builder with a script. |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2016 10:41 PM |
well i kinda did cuz i said they could use a remote event
you can do it either way though because if filtering is enabled it kinda ruins the idea of a script builder or if filtering is enabled but they use server sided code, you get the idea |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2016 10:46 PM |
| only certain people will have access to this place |
|
|
| Report Abuse |
|
|
| |
|
|
| 10 Nov 2016 10:47 PM |
@Wunder_Wuffle
Yeah pcall is pretty cool
"print(pcall(loadstring("peieodk('lol')")))"
But, how would I make it pcall the text?
|
|
|
| Report Abuse |
|
|
| |
|
|
| 10 Nov 2016 10:48 PM |
pcall executes a function and returns if it ran or not and the error it had loadstring already returns a function so load the string and use pcall for execution |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2016 10:49 PM |
heres an example
textbox.FocusLost:connect(function() print(pcall(loadstring(textbox.Text)))--print the output end) |
|
|
| Report Abuse |
|
|
|
| 10 Nov 2016 10:56 PM |
Thanks so much! I ended up with this
script.Parent.GO.MouseButton1Down:connect(function() --b.FocusLost:connect(function() print(pcall(loadstring(b.Text)))--print the output --end) local ss = (pcall(loadstring(b.Text))) if ss == true then loadstring(b.Text)() end -- end end)
and it works.
|
|
|
| Report Abuse |
|
|
|
| 10 Nov 2016 10:57 PM |
try this instead so you can see an example:
local ss,err = (pcall(loadstring(b.Text))) if ss == true then loadstring(b.Text)() else warn([[Error executing code: "]]..err..[["]]) end |
|
|
| Report Abuse |
|
|
| |
|