How to Execute Lua in a Textbox

Hello, I’m trying to figure out how to use loadstring() to execute a script from a textbox when a button is clicked.
Here’s what it would look like.
text

Try using this:

loadstring(Code)()

Note loadstring is dangerous to use because you can accidentally expose yourself to allowing people to run unauthorized code on your client!

loadstring can not be called from the client directly.

You will have to try using the Rerubi open source module, or enable loadstring relevant property of ServerScriptService then call the function on the Server’s context.

You will also likely have to use a remote event to send the data to the server. So when the client presses the button you send the value of the text.

Here is some example code you could use to write your own code:

--// Client

button.MouseButton1Click:Connect(function()
    remoteEvent:FireServer(input.Text)
end)

--// Server

remoteEvent.OnServerEvent:Connect(function(player, code)
    local func = loadstring(code)

    func()
end)

I suggest only allowing specific people to access this unless you’re making a script builder. If you are making a script builder I suggest you learn more about code sandboxing. If this is meant to just be for you to execute code then I greatly suggest you check who is firing the remote event.

--// Client

button.MouseButton1Click:Connect(function()
    remoteEvent:FireServer(input.Text)
end)

--// Server

remoteEvent.OnServerEvent:Connect(function(player, code)
    if (player.Name == "FaZe_5421") then --// only you should be able to run code!
        local func = loadstring(code)

        func()
    end
end)

If you don’t want to enable loadstring, you can use a Lua VM Module

On the topic of that I might as well mention Rerubi and FiOne’s source.

https://github.com/Rerumu/Rerubi
https://github.com/Rerumu/FiOne (Use this instead of Rerubi)

It says “FireServer can only be called from the client”.

And it’s correct. You’re supposed to be using the code that is meant to be on the client in a LocalScript and the code that is meant to be in a script in a Script.