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

How do I execute a string as a piece of code?

Asked by 5 years ago

How do I execute a string as a piece of code? For example, if I have: x = "print('hello')" is there a function that would let me do something like run(x) ?

0
Can you give an example where this would be useful? I would just do print("hello") MegaManSam1 207 — 5y
0
@MegaManSam1, load script from pastebin. Do you know a way to do this? devisings 58 — 5y
0
I don't, sorry. MegaManSam1 207 — 5y

2 answers

Log in to vote
-1
Answered by
Mr_Unlucky 1085 Moderation Voter
5 years ago
Edited 5 years ago

There is a feature in Roblox called "LoadString" in which you can execute code. However, this is used by exploiters to exploit in your game, so please be careful when doing this.

In order to enabled "LoadString", go check the box in the properties of ServerScriptService.

loadstring()

Here's the link if you're interested.

0
Thank you. Annitially I had the loadstring enabled in ServerScriptService and I tried it and it wasn't working. But apparently doing 'loadstring(x)()' works but 'loadstring(x)' doesn't. So thank you for that link. devisings 58 — 5y
0
What? Hackers can already hack your game even if loadstring is disabled. They have access to the Roblox executable and access to their computer which the software is running on. It's also in the developer wiki here https://developer.roblox.com/api-reference/lua-docs/Lua-Globals hiimgoodpack 2009 — 5y
0
who downvoted this even tho it's right... ZzZzZZZzzz NickAtNick 163 — 5y
0
did you not read the above comment? hiimgoodpack 2009 — 5y
View all comments (2 more)
0
hmmm. Strange, I thought I read it correctly. NickAtNick 163 — 5y
0
Sorry for the mistakes. I searched it up on the developer wiki and no hits came up. Mr_Unlucky 1085 — 5y
Ad
Log in to vote
-1
Answered by 5 years ago
Edited 5 years ago

Yes there is, Let's take PlayerAdded as an example. Your function:

 function printing(String)
    print(String)
    end

PlayerAdded: So when a player is added, it will call the function above ^^ and print the String that is written in the parameter of the called function below vv

Players.PlayerAdded:Connect(function(player)
printing(player.Name.." has joined the server!")
end)

Comment if there is any confusion.

0
I may have misunderstood the original question, but this is just concatenating two strings, i think they want to know if you can actually run a string as code. MegaManSam1 207 — 5y
0
Correct ^ devisings 58 — 5y
0
Oh. Then Since roblox is running on Lua maybe this can help you: https://stackoverflow.com/questions/44386060/execute-lua-string-as-lua-code NickAtNick 163 — 5y
0
I've tried this. I should mention I've enabled 'LoadStringEnabled' inside serverscriptservice. But I get nothing. No errors and also nothing from the 'print()'. So I don't know whats wrong... devisings 58 — 5y

Answer this question