Recently, with a small help (help page), I have made a Script that detects when there was a Script Error. The code looks similar to this:
game:GetService("ScriptContext").Error:Connect(function(message, trace, script)
local name = script.Name
if name == "NameOfMyScript" then
end
end)
I want to do the same thing but with detecting Script warnings. I searched DevForum a lot but I still don’t know how to do it. Every help would be appreciated.
Thanks.
I tried using LogService but I don’t know how to detect what Script have made a warning. Here’s my code that uses LogService:
game:GetService("LogService").MessageOut:Connect(function(Message, Type)
if Type == Enum.MessageType.MessageWarning --[[and WhatScriptHaveMadeAWarning.Name == "My Script's Name"]]then
end
end)
To make it work using LogService, one way would be to have an identifier at the beginning of the string
LogService.MessageOut:Connect(function(message, Type)
if Type == Enum.MessageType.MessageWarning then
local msg = message:match("_fromMyScript")
if msg then
print("warn from _fromMyScript") -- you can utilize simple string manipulation to get just the message e.g string.sub, string.match ...
end
end
end)
warn("_fromMyScript this is a warn") -- include an identifier "__fromMyScript"
though it would be a terrible choice under normal circumstances to rely on this for any game logic, I think it said this in the API reference too.
These blue messages seems to have info of what script have caused the warning.
I made a script that scans every message in the logs and checks for GameProgressService text. Here is the script:
game:GetService("LogService").MessageOut:Connect(function(message)
local name = message:match("GameProgressService")
if name then
end
end)
Thanks again for @XxELECTROFUSIONxX and @Blokav help!