How to loadstring() without actually running the code

I wanted to make a real time error checker for my in-game IDE, and I already know how to do it but I had a problem
The error checker worked… but it also executed the code
Screen Shot 2564-05-25 at 11.25.02 AM
I tried looking for help but didn’t find any from online source
this was my code

ErrorCheckerRemote.OnServerEvent:Connect(function(Player, Code)
	local Success, Error = pcall(function()
		loadstring(Code)
	end)

	if Success then
		print(Code)
		print("no error")
	else
		print(Error)
	end
end)

it printed the code and printed no error then I fire the remote event and the code is

print("hi")

the problem is it also ran the code print(“hi”) and I don’t want it to run, only check
any help? or ideas?

-- not running
loadstring('print(\'hello world\')')

-- running
loadstring('print(\'hello world\')')()

I did

loadstring(Code)

and

loadstring(Code)()

they both are the same, it both ran the code

what?? i didn’t know that’s a thing :flushed:

this is my code

		local Success, Error = pcall(function()
			loadstring(Code)
		end)

		if Success then
			print(Code)
			print("no error")
		else
			print(Error)
		end

and the code that it checks was

print("hi")

even if I add () or remove () on the loadstring(), it will still run the code
Screen Shot 2564-05-25 at 11.34.02 AM

can you give me the whole code, i want to see what’s wrong

also why the “hi” message is from the studio? it should be from a script

ErrorCheckerRemote.OnServerEvent:Connect(function(Player, Code)
	local Success, Error = pcall(function()
		loadstring(Code)
	end)

	if Success then
		print(Code)
		print("no error")
	else
		print(Error)
	end
end)

sorry I forgot to save the script, it works!
but instead… it print “no error” even when the code that it checks have error

this is the code that it checks

print("hi)

Screen Shot 2564-05-25 at 11.40.15 AM

because you didn’t call the loadstring function
i mean:

loadstring('print("hi)')()

yes
I did

ErrorCheckerRemote.OnServerEvent:Connect(function(Player, Code)
	local Success, Error = pcall(function()
		loadstring(Code)()
	end)

	if Success then
		print(Code)
		print("no error")
	else
		print(Error)
	end
end)

but… it ran the code when it checks
the thing is I only want it to check, I don’t want it to run the code is that possible??
Screen Shot 2564-05-25 at 11.42.32 AM

use my module instead, i forgot how to use it link lol

local module = require(--[[module location]])

local output, isError = module:Compile(
  "print('hello world')",
  "lua-5.4.0"
)

if isError then
  print('error xdxd')
else
  print(output)
end

doesn’t use loadstring

I will try it out, thanks:D will tell if it works

I tried

ErrorCheckerRemote.OnServerEvent:Connect(function(Player, Code)
	local module = require(script.MainModule)

	local output, isError = module:Compile(
		'print("hi")',
		"lua-5.4.0"
	)

	if isError then
		print('error xdxd')
	else
		print(output)
	end
end)

it printed “error xdxd” every time the remote event fire (but it delay a bit)

my module post data to a web api, lol

I had http request and allow studio access to API services turned on

try

print('hello')

and

print('hello)

I tried that, it both printed ‘error xdxd’

omg I tried that againn and it worked! TYSMMM

this was my code btw
ErrorCheckerRemote.OnServerEvent:Connect(function(Player, Code)
	pcall(function()
		print(Code)
		local suc,err = loadstring(tostring(Code))
		
		if suc then
			print("suc")
		else
			print("err")
		end
	end)
end)