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

[solved] invalid argument #3 (string expected, got function)? What?

Server script (where the error is coming from) inside of ServerScriptService:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
	local text = tostring(game.ReplicatedStorage.Value.Value)
	game.ReplicatedStorage.Value2.Value = loadstring(text)
end)

Local script inside of StarterGui (no errors):

while true do
	wait()
	local tocompile = script.Parent.Text
	game.ReplicatedStorage.RemoteEvent:FireServer()
	game.ReplicatedStorage.Value.Value = script.Parent.Text
	wait()
	script.Parent.Parent.TextLabel.Text = game.ReplicatedStorage.Value.Value
end

Anyone know why this is happening?

P.S. When using a print(text) in the serverscript it prints print("Hello world"), which is the value but that would mean that loadstring() isn't working.

EDIT:

Server script (where the error is coming from) inside of ServerScriptService:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr, text)
	loadstring(text)()
end)

Local script inside of StarterGui (no errors):

while true do
	wait()
	game.ReplicatedStorage.RemoteEvent:FireServer(script.Parent.Text)
end

How do you change the textlabels text to the loadstring instead of just printing it?

1 answer


Client Code:

####With the assuming structure:

####ScreenGui -> TextBox -> TextButton -> TextLabel

--###----------[[SERVICES]]----------###--
local ReplicatedStorage = game:GetService("ReplicatedStorage")



--###----------[[VARIABLES]]----------###--
local CompileCode = ReplicatedStorage:WaitForChild("CompileAndExecute")


local GUIMain = script.Parent

local CodeForm = GUIMain:WaitForChild("CodeForm")

local CompileButton = CodeForm:WaitForChild("CompileButton")
local OutputText = CompileButton:WaitForChild("OutputText")



--###----------[[FUNCTIONS]]----------###--
local function OnButtonClick()
	local CodeToCompile = CodeForm.Text
	---------------
	local CompiledSuccessfully, ExecutionResult = CompileCode:InvokeServer(CodeToCompile)
	---------------
	OutputTextLabel.Text = "Compiled with exit code "..(CompiledSuccessfully and 0 or 1).."! "..(ExecutionResult or '')
end



--###----------[[SIGNALS]]----------###--
CompileButton.MouseButton1Click:Connect(OnButtonClick)

Server Code:

--###----------[[SERVICES]]----------###--
local ReplicatedStorage = game:GetService("ReplicatedStorage")



--###----------[[VARIABLES]]----------###--
local ExecuteCode = ReplicatedStorage:WaitForChild("CompileAndExecute")


local ErrorFormatTemplate = "(%d: .*)"



--###----------[[FUNCTIONS]]----------###--
local function OnCodeRecieved(_, Code)
	local Executable, Error = loadstring(Code)
	---------------
	if not (Error) then
		---------------
		Executable()
		---------------
		return true
	else
		return false, Error:match(ErrorFormatTemplate)
	end
end



--###----------[[SIGNALS]]----------###--
ExecuteCode.OnServerInvoke = OnCodeRecieved

7 comments

0

Ok, I just need to know how I would set a textlabels text to the loadstring?

0

Why would that be necessary?

0

Still lost.

0

Like making a completely gui based compiler, so the output is a textlabel.

0

That's the best I can do for you, the rest I believe will be orientated around LogService.

0

Sorted it myself with logservice and messageout.

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