Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

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
0
Ok, I just need to know how I would set a textlabels text to the loadstring? WideSteal321 773 — 3y
0
Why would that be necessary? Ziffixture 6913 — 3y
0
Still lost. Ziffixture 6913 — 3y
View all comments (3 more)
0
Like making a completely gui based compiler, so the output is a textlabel. WideSteal321 773 — 3y
0
That's the best I can do for you, the rest I believe will be orientated around LogService. Ziffixture 6913 — 3y
0
Sorted it myself with logservice and messageout. WideSteal321 773 — 3y
Ad

Answer this question