I’m currently working on a scam detection system, however I cannot get the system messages to send at all. Could anyone assist me on this?
local Players = game:GetService("Players")
local TextChatService = game:GetService("TextChatService")
local localPlayer = Players.LocalPlayer
if TextChatService.ChatVersion ~= Enum.ChatVersion.TextChatService then
warn("Scam filter requires the new TextChatService to be enabled!")
return
end
local scamPatterns = {
-- Free Robux scams
"free robux", "freerobux", "free r$", "freer$",
"claim robux", "get robux", "earn robux", "robux generator",
"free rbx", "freerbx",
-- Phishing sites
"blox", "rbx", "rblx", "robox", "robIox",
"rewards", "rewαrds", "rewords", "clαim",
-- Discord bypasses
"disc", "dscrd", "discοrd", "dis cord",
"d1scord", "d!scord",
-- Other platforms
"youtube%.com", "youtu%.be", "twitter%.com",
"tiktok%.com", "twitch%.tv",
-- Suspicious phrases
"click here", "visit", "join now", "limited time",
"hurry", "expires", "go to", "check out",
-- Fake system messages
"%[system%]", "%[roblox%]", "%[admin%]",
-- Common scam phrases
"become admin", "get admin", "free admin",
"hack", "exploit", "cheat",
"account giveaway", "giving away"
}
local function containsScam(message)
local lowerMsg = message:lower()
local noSpaces = lowerMsg:gsub("%s+", "")
for _, pattern in ipairs(scamPatterns) do
if lowerMsg:match(pattern) or noSpaces:match(pattern) then
return true
end
end
if lowerMsg:match("https?://") or lowerMsg:match("www%.") or
lowerMsg:match("%.com") or lowerMsg:match("%.gg") then
return true
end
local specialCharCount = select(2, lowerMsg:gsub("[^%w%s]", ""))
if specialCharCount > 5 then
return true
end
return false
end
local function sendWarning(isSelf)
local textChannels = TextChatService:WaitForChild("TextChannels")
local channel = textChannels:WaitForChild("RBXGeneral")
local warningText
if isSelf then
warningText = "[SCAM FILTER] ⚠️ Your message contains potentially dangerous content!"
else
warningText = "[SCAM ALERT] ⚠️ Be careful! This message may contain scams. Never share your account info!"
end
pcall(function()
local systemMessage = TextChatService:CreateDefaultTextChannelSystemMessage({
Text = warningText,
Font = Enum.Font.GothamBold,
Color = isSelf and Color3.fromRGB(255, 150, 0) or Color3.fromRGB(255, 0, 0),
FontSize = 17
})
channel:DisplaySystemMessage(systemMessage)
end)
end
local function onMessageReceived(textChannel, message)
if message.TextSource then
local player = Players:GetPlayerByUserId(message.TextSource.UserId)
if player and containsScam(message.Text) then
local isSelf = (player == localPlayer)
sendWarning(isSelf)
end
end
end
local function setupChannel(channel)
if channel then
channel.MessageReceived:Connect(function(message)
onMessageReceived(channel, message)
end)
end
end
repeat task.wait() until game:IsLoaded()
task.wait(2)
local textChannels = TextChatService:WaitForChild("TextChannels")
for _, channel in ipairs(textChannels:GetChildren()) do
if channel:IsA("TextChannel") then
setupChannel(channel)
end
end
textChannels.ChildAdded:Connect(function(child)
if child:IsA("TextChannel") then
setupChannel(child)
end
end)