Is there any way to make an in-game script writing system?

So I want to make some kind of script writing system that allows player to write their script (not exploit) in the game and their script can also work in the game. It just like how we script in roblox studio normally but now its in a game. That’s ok if there’s no way I can make that, Cheers!

1 Like

Hello, you can try with loadstring

loadstring("print('Hello This is a test')")()

A More Complex Example:

local MyVar = "Testing"

loadstring("print('" .. MyVar .. "')")()

boatbomber (creator of Lua Learning) has made a fantastic project that answers your question.

2 Likes

tried this in my script. Is this how it works?

local typescript = run.Parent.ScrollingFrame.TextBox
local outputtext = run.Parent.OutputText

run.MouseButton1Click:Connect(function()
	if typescript.Text == 'print("Hello world!")' then
		outputtext.Text = loadstring("print('Hello world!')")()
	end
end)

this also gives me an error
image

anyways, this is a localscript parented in a textbutton that will execute the script typed in the textbox

Enable it: ServerScriptService.LoadStringEnabled

ServerScriptService → property → LoadStringEnabled = true
And Yes of course loadstring must be called and used in ServerScriptService, You can’t use loadstring on client for a security reason I think,
Probably if you allow it to be used in the client it would lead to problems with exploits

1 Like

I didn’t do with loadstring but I think must be in server script, because when you look at ServerScriptService there is a LoadStringEnable.

local typescript = run.Parent.ScrollingFrame.TextBox
local outputtext = run.Parent.OutputText

run.MouseButton1Click:Connect(function()
	if typescript.Text == 'print("Hello world!")' then
		local NewText = 'print("Hello world!")'
		game.ReplicatedStorage.RemoteEvent:FireServer(NewText,outputtext)
	end
end)
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, NewText,outputtext)
	loadstring(NewText)()
	outputtext.Text = NewText
end)
1 Like

this works pretty well, but it shows this error image when I change the NewText into a StringValue.Value

You have to write it in the textbox just as you would write it in the script.
Instead 'print("Hello world!")' this print("Hello world!") .
And if the code(text) in the textbox is wrong, you can warn the player like this:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, Code,outputtext)	
	pcall(function()
		local suc,err = loadstring(Code)
		if suc then
			loadstring(Code)()
			outputtext.Text = Code
		else
			warn("ERROR")
		end
	end)
end)

I typed the exact same code print(“Hello world!”) in the textbox. But it doesn’t give me the output Hello world!, instead it always give me the warn

Can you show me your local script?

sorry for the late reply, I still have school

local typescript = run.Parent.ScrollingFrame.TextBox
local outputtext = run.Parent.Output
local ip         = game:GetService("Players").LocalPlayer:WaitForChild("Data"):WaitForChild("IP")
local ipvalue    = ip.Value

run.MouseButton1Click:Connect(function()
	wait(2)
	if typescript.Text == "ipconfig/view" then
		local Code  = ipvalue 
		game.ReplicatedStorage.CMD:FireServer(Code,outputtext)
	end
end)

I changed it a little bit. If you don’t understand, I’ll explain this script. So I want to make a gui like command prompt in windows, when player typed ipconfig/view then the output will give the player’s ip (not real ip, its just a StringValue in the game). I tested by typing that and it doesn’t give any output.

can you please include your server script as well?

Also, try putting a print() statement after the in the if statement (before the local code = ) bit

the server script is above and same as @CharranCZ’s reply

And are there any warnings / errors appearing?

it gives “ERROR” warning from the server script even though I typed ipconfig/view correctly

In the server script, can you please add

warn(err)

after

warn("ERROR")

then tell me what it says

image
like that?

it also gives this warn
image
(the 182.231.166.193 is the ip/stringvalue. Again, it is not a real ip)

Are you adding print() into the code when you are inputting it?

in the localscript? yes I did like you said before.
image

What exactly is the value of ipvalue? Is it just the IP, or is it print(182.231.116…)