Mute players with TextChatService

A better way to do this server side would be to mute any current and future TextSources that match a userId:

local TextChatService = game:GetService("TextChatService")

local function muteUserId(mutedUserId)
    -- listen for future TextSources
    TextChatService.DescendantAdded:Connect(function(child)
        if child:IsA("TextSource") then
            if child.UserId == mutedUserId then
                child.CanSend = false
            end
        end
    end)

    -- mute any current TextSources
    for _, child in TextChatService:GetDescendants() do
        if child:IsA("TextSource") then
            if child.UserId == mutedUserId then
                child.CanSend = false
            end
        end
    end
end

this can run on the server

11 Likes