How would I run code that the player types into the textbox?

I want to have the player enter code into a textbox and then have that code run. I also want the results to be shown in an in-game output.

How would I go about doing this?

I did a bit of investigation and found a Loadstring module (since the common loadstring() didn’t work for me even if it was enabled), it’s very easy to use:
vLua 5.1 (improved VM) - Roblox (credits to their respective creators)

You just need to require it to make it work, and here is an example of how it works:

local textbox = script.Parent -- where your textbox is located

textbox.FocusLost:Connect(function(enterPressed)
	local plrText = textbox.Text
	
	if enterPressed then
		local Loadstring = require(workspace.Loadstring) -- where the module is located
		Loadstring(plrText)() -- returns a function
		print(plrText)
	end
end)

Hope it helps!

1 Like

Thanks, I’ll try this out.