How do I convert the result of a function into a string lua

I’m sorry for asking to many questions here but how would I do that
image
image

I think you should learn Lua before trying to take on this project… This is pretty basic stuff. The user might not always return a value so in that case you need to handle if executeCode() returns a nil value.

No but I put a valid command and it still returned nil its able to print the function just fine but it returns nil when I try to apply it to text

EDIT: after further work it turns out that whatever command I set the functions string to be it will always return nil except if I print it the function as if I print it it will print 2 versions. One will be blank and says it executed on the line 8 where my print function is and the other one will be the result of the function correctly printed but says it was executed on line 1?


image

local executeCode = loadstring('...')()
print(executeCode())

Try maybe to remove the () to the loadstring end

That just prints the location of the function

Are you trying to make it return “oof” when you run print("oof")?

yes that’s exactly it. the reason i put oof was because it was the first thing i thought off i can make it anything but i just choose oof

You could try overriding the built in print function with a custom one that writes stuff on your textlabel

local TextLabel = workspace.Baseplate.SurfaceGui.TextLabel

local function print_custom(...)
	TextLabel.Text = TextLabel.Text .. "\n" .. table.concat({...}, " ")
end

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player, Code)
	local old_print = print
	print = print_custom
	local f = loadstring(Code)
	print = old_print
	f()
end)

That’s great but I really want this to run actual Lua as I think just writing custom commands for every Lua command would be very time consuming compared to just making it run actual Lua and not just a bunch of custom commands. the things suppose to run most lua commands not just print

You could do the same thing with things returned from the function. print doesn’t return anything, it just writes text to the output. I don’t see how this isn’t running “actual Lua”

local result = loadstring("return 2 + 2")()
if result then
    TextLabel.Text ..= "\n" .. tostring(result)
end

The result is now returning nil even though even though it can print the string fine

Update I know this post is dead but I would just like to say Thanks to everyone who helped me as I finally got this running