Textbox as in-game code runner

Is there a way? thank you. I already do it with LuaVM (Parser without Loadstring) and also already try to use Loadstring and it works, but how to put the output in the GUI.

I finally work with LogService.MessageOut or is there any better idea?

But using LogService.MessageOut has bug, is like the first time I run, yes it only make 1 textlabel on the output, but the second time it make two textlabels, and the third time, it make three textlabels.

Yes, but now that I think about it it’s probably better to just use LogService:GetLogHistory(), because LogService.MessageOut will fire multiple times, while you can just get the log history right before and after calling the loadstring, and then compare them to get only what is from the loadstring.

But how to use this LogService:GetLogHistory()
because using LogService.MessageOut it’s only like,

-- if Using Rerubi / LuaVM
local test = require(Modules)(Text)
test()
LogService.MessageOut:Connect(function(Message, Type)
	local TextLabel = game.ReplicatedStorage.Output:Clone()
	TextLabel.Text = Message
	TextLabel.Parent = Player.PlayerGui.NC.Output.ScrollingFrame
end)

-- if using Loadstring
local test = loadstring(Text)
test()
LogService.MessageOut:Connect(function(Message, Type)
	local TextLabel = game.ReplicatedStorage.Output:Clone()
	TextLabel.Text = Message
	TextLabel.Parent = Player.PlayerGui.NC.Output.ScrollingFrame
end)

How to use this GetLogHistory?

Let me record and show you what happen when I use MessageOut.

You can use it like so:

local LogService = game:GetService("LogService")

local function compare(table1, table2)
	local table1Length = #table1
	local table2Length = #table2

	local differences = {}

	for i, v in ipairs(table1) do
		if table1Length > table2Length then
			if i > table2Length then
				table.insert(differences, v)
			end
		end
	end

	return differences
end

local loadstr = loadstring(Text)
local historyLog1 = LogService:GetLogHistory()

loadstr()

local historyLog2 = LogService:GetLogHistory()
local result = compare(historyLog2, historyLog1)

for _, message in ipairs(result) do
	local TextLabel = game.ReplicatedStorage.Output:Clone()
	TextLabel.Text = message.Message
	TextLabel.Parent = Player.PlayerGui.NC.Output.ScrollingFrame
end

Yes but how to make it appliable for many times. I’ll give you the video.


This

Is this using MessageOut or GetLogHistory?

I want to make everytime the play button press it only make one textlabel only, so it’s gonna be like 1,1,1 if we press three times, not like 1,2,3 textlabels

MessageOut, if using GetLogHistory for every press button, just use your code? It works for everytime?

Well I use clone because it’s easier rather than Instance.new because I use this only for testing.

I don’t use one textlabel because if it’s a lot is gonna be full, because I use ScrollingFrame with auto scale?

Sorry I just realized a mistake in the code, I just edited it

But I suppose after you see my video, you can understand what I’m trying to do.

Yes, I already understood what you’re trying to do, and if you use my code then it should work

Idk why it doesn’t clone to my GUI, this is my entire script, well I know I can use LocalScript but I use FireServer as testing here, but it doesn’t clone the text to the gui but the loadstring part works.

This is full script using your code.

-- Server Script
local RemoteEvent = game.ReplicatedStorage.Test
local Modules = game.ReplicatedStorage.Loadstring
local LogService = game:GetService("LogService")

local function compare(table1, table2)
	local table1Length = #table1
	local table2Length = #table2

	local differences = {}

	for i, v in ipairs(table1) do
		if table1Length > table2Length then
			if i > table2Length then
				table.insert(differences, v)
			end
		end
	end

	return differences
end


RemoteEvent.OnServerEvent:Connect(function(Player, Text)
	local test = loadstring(Text)
	local historyLog1 = LogService:GetLogHistory()
	test()
	local historyLog2 = LogService:GetLogHistory()
	local result = compare(historyLog2, historyLog1)
	for _, message in ipairs(result) do
		local TextLabel = game.ReplicatedStorage.Output:Clone()
		TextLabel.Text = message.Message
		TextLabel.Parent = Player.PlayerGui.NC.Output.ScrollingFrame
	end
end)

-- Local Script
local TextBox = script.Parent.Parent.Parent.TextBox
local Button = script.Parent
local RemoteEvent = game.ReplicatedStorage.Test
local Players = game:GetService("Players")
local Player = Players.LocalPlayer

Button.MouseButton1Click:Connect(function()
	RemoteEvent:FireServer(TextBox.Text)
end)

Previously my code is similar like this, just I use MessageOut.

My previous code only change on this part

RemoteEvent.OnServerEvent:Connect(function(Player, Text)
	local test = loadstring(Text)
	test()
	LogService.MessageOut:Connect(function(Message, Type)
		local TextLabel = game.ReplicatedStorage.Output:Clone()
		TextLabel.Text = Message
		TextLabel.Parent = Player.PlayerGui.NC.Output.ScrollingFrame
	end)
end)

It just it doesn’t clone the textlabel.