Stack tracing with print

Hello, I’m currently trying to make an anti-exploit and I’m trying to detect when an exploiter prints a message into the output. Using ScriptContext.Error, I can detect when a script errors and I can get the path of the script like this:

game:GetService("ScriptContext").Error:Connect(function(message, stackTrace, object)
	print(stackTrace) -- Prints the path of the script that errored
end)

What I’m trying to do is similar to this but instead of getting the stack trace of an error, I want to get the stack trace of a print.

game:GetService("LogService").MessageOut:Connect(function(message)
	print(message)
end)

This function above can get when a script prints a message but there is no parameter available to get the script that called the print function. I’m wondering if there is any way to find the script that called the print function. Thanks!

You can call traceback() debug | Roblox Creator Documentation

1 Like

This is the script I have. It’s just returning the line of the script that called the debug.traceback() function.

game:GetService("LogService").MessageOut:Connect(function(message, messageType)
	if messageType == Enum.MessageType.MessageOutput then
		local traceback = debug.traceback()
		warn(traceback)
	end
end)

Please read the full description of the function on the page I linked.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.