generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Textbox that executes code that you type in it?

Previous Thread :: Next Thread 
DaCrazyDev is online. DaCrazyDev
Joined: 28 Sep 2013
Total Posts: 134
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
DaCrazyDev is online. DaCrazyDev
Joined: 28 Sep 2013
Total Posts: 134
10 Nov 2016 08:23 PM
@Wuner_Wufle

Thanks, but how would I use loadstring?

And how would I make a parser?
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Real_Spooky is not online. Real_Spooky
Joined: 23 Oct 2013
Total Posts: 3149
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
DaCrazyDev is online. DaCrazyDev
Joined: 28 Sep 2013
Total Posts: 134
10 Nov 2016 08:29 PM
@Real_Spooky

I agree, I don't even know what it IS...
Report Abuse
DaCrazyDev is online. DaCrazyDev
Joined: 28 Sep 2013
Total Posts: 134
10 Nov 2016 08:29 PM
@Wunder_Wuffle

Thank you!
Report Abuse
DaCrazyDev is online. DaCrazyDev
Joined: 28 Sep 2013
Total Posts: 134
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
DaCrazyDev is online. DaCrazyDev
Joined: 28 Sep 2013
Total Posts: 134
10 Nov 2016 08:35 PM
yep thats how, thanks so much lol
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
DaCrazyDev is online. DaCrazyDev
Joined: 28 Sep 2013
Total Posts: 134
10 Nov 2016 08:53 PM
thx and pieodk is nil LOL
Report Abuse
DaCrazyDev is online. DaCrazyDev
Joined: 28 Sep 2013
Total Posts: 134
10 Nov 2016 08:54 PM
how about error() instead of print() tho?
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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 is not online. 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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
DaCrazyDev is online. DaCrazyDev
Joined: 28 Sep 2013
Total Posts: 134
10 Nov 2016 10:46 PM
only certain people will have access to this place
Report Abuse
DaCrazyDev is online. DaCrazyDev
Joined: 28 Sep 2013
Total Posts: 134
10 Nov 2016 10:46 PM
or the gui
Report Abuse
DaCrazyDev is online. DaCrazyDev
Joined: 28 Sep 2013
Total Posts: 134
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
DaCrazyDev is online. DaCrazyDev
Joined: 28 Sep 2013
Total Posts: 134
10 Nov 2016 10:48 PM
@Wunder_Wulfe
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
10 Nov 2016 10:49 PM
heres an example

textbox.FocusLost:connect(function()
print(pcall(loadstring(textbox.Text)))--print the output
end)
Report Abuse
DaCrazyDev is online. DaCrazyDev
Joined: 28 Sep 2013
Total Posts: 134
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
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
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
DaCrazyDev is online. DaCrazyDev
Joined: 28 Sep 2013
Total Posts: 134
10 Nov 2016 11:02 PM
okay, thanks again.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 3Go to page: [1], 2, 3 Next
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image