Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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) ?

3 comments

0

Can you give an example where this would be useful? I would just do print("hello")

0

@MegaManSam1, load script from pastebin. Do you know a way to do this?

0

I don't, sorry.

2 answers

✓ Accepted answer

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.

6 comments

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.

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

0

who downvoted this even tho it's right... ZzZzZZZzzz

0

did you not read the above comment?

0

hmmm. Strange, I thought I read it correctly.

0

Sorry for the mistakes. I searched it up on the developer wiki and no hits came up.

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.

4 comments

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.

0

Correct ^

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

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...

This discussion is preserved as it was. New answers, comments, and votes are closed.