#adding a textfilter to global message system

1 messages · Page 1 of 1 (latest)

covert lagoon
#

so a while ago my friend made me a global messaging systemm, im wondering how to add the roblox text filter to it?

local MessagingService = game:GetService("MessagingService")
local StarterGui = game:GetService("StarterGui")
local Chat = game:GetService("Chat")

local authorizedUsers = require(game.ReplicatedStorage.Admins)
local globalMessageTopic = "GlobalMessage"

local function sendGlobalMessage(player, message)
    if not table.find(authorizedUsers, player.UserId) then
        player:Kick("Unauthorized access to global messaging system.")
        return
    end

    if type(message) ~= "string" or message == "" then
        return
    end

    local success, errorMessage = pcall(function()
        MessagingService:PublishAsync(globalMessageTopic, {
            text = message,
        })
    end)

    if not success then
        warn("Failed to publish message: " .. errorMessage)
    end
end

Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(message)
        if string.sub(message, 1, 9) == "/message " then
            local content = string.sub(message, 10)
            if content and content ~= "" then
                sendGlobalMessage(player, content)
            end
        end
    end)
end)

local function displayGlobalMessage(player, text)
    local playerGui = player:WaitForChild("PlayerGui", 10)
    if not playerGui then
        return
    end

    local globalAnnouncement = playerGui:FindFirstChild("GlobalAnnouncement")
    if not globalAnnouncement then
        local starterGuiClone = StarterGui:FindFirstChild("GlobalAnnouncement")
        if starterGuiClone then
            globalAnnouncement = starterGuiClone:Clone()
            globalAnnouncement.Parent = playerGui
        else
            return
        end
    end

    local textLabel = globalAnnouncement:WaitForChild("Frame"):FindFirstChild("Message")
    local frame = textLabel.Parent
    if textLabel then
        frame.Visible = true
        textLabel.Text = text
        textLabel.Visible = true
        

        task.delay(5, function()
            if textLabel then
                frame.Visible = false
                textLabel.Visible = false
                
            end
        end)
    end
end

local function onGlobalMessageReceived(message)
    if type(message) ~= "table" or not message.text then
        return
    end

    for _, player in pairs(Players:GetPlayers()) do
        displayGlobalMessage(player, message.text)
    end
end

local success, errorMessage = pcall(function()
    MessagingService:SubscribeAsync(globalMessageTopic, function(data)
        if data and data.Data then
            onGlobalMessageReceived(data.Data)
        end
    end)
end)

if not success then
    warn("Failed to subscribe to global messages: " .. errorMessage)
end
tough wagon
#

ask it to your friend bro

covert lagoon
#

he doesnt know scripting anymore

#

this was a while ago

tough wagon
covert lagoon
#

Thanks