ChatService ChatChannel:MuteSpeaker() usage

I want to be able to mute players using the standard Roblox Chat Service’s ChatChannel:MuteSpeaker function.

The problem is, despite the system printing logs that indicate that the muting of a player worked, the player can still speak.

I looked at the documentation for ChatChannel and then added a module to Chat/ChatModules with the following code. Despite the code printing out that the player was muted for “being evil” and printing out “MUTED” indicating that the SpeakerMuted event fired, the player is still able to speak.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage:WaitForChild("Events")
local MuteBindableEvent = Events:WaitForChild("MuteBindableEvent").Event

local Run = function(ChatService)
    ChatService.ChannelAdded:Connect(function(channelName)
        local channel = ChatService:GetChannel(channelName)

        MuteBindableEvent:Connect(function(plr, shouldMute)
            if shouldMute then
                channel:MuteSpeaker(plr.Name, "being evil", 500)
            else
                channel:UnmuteSpeaker(plr.Name)
            end
        end)

        channel.SpeakerMuted:Connect(function(name, reason, t)
            print("MUTED", name, reason, t)
        end)

        channel.SpeakerUnmuted:Connect(function(name)
            print("UNMUTED " .. name)
        end)
    end)
end

return Run
4 Likes

You just mute them from the “ALL” channel. Use ChatService:GetChannel() for this one.

local channel = ChatService:GetChannel("ALL")
-- somewhere else in your code
channel:MuteSpeaker(--[[some name]])
-- to unmute
channel:UnmuteSpeaker(--[[some name]])
10 Likes

YOU’RE RIGHT!!!

For some reason I didn’t actually print the channel name until this moment. I didn’t realize that ChannelAdded does not fire for “ALL” but does fire for “Team”.

2 Likes

This is because the All channel is the default channel created when the Lua Chat System is initialised up, but not Team. Team chatting functionality is created through the addition of chat widgets, not as a hard coded part of the system, for which you can remove. The related modules are called after the system finishes starting up which respectively establish the ability to communicate within your own team.

3 Likes

Yep! For some reason it wasn’t clicking until now, but I see clearly at the top of the ChatChannel wiki that it says, By default, each player has a ChatSpeaker that is automatically added to the “All” and “System” chat channels. Thanks :slight_smile:

I guess in my mind that didn’t initially imply that those chats were loaded without firing the ChatAdded event.

Hi,
I have a question, how exactly are you getting ChatService?

Please read the thread.

There’s boilerplate for ChatModules in the Lua Chat System documentation. The chat system calls ChatModules and passes the ChatService singleton as an argument. ChatModules should return a single-parameter function on require for the ChatService.

2 Likes

If a script is in ServerScriptService, you could just do

local ChatService = script.Parent:WaitForChild("ChatServiceRunner").ChatService

As @colbert2677 also said, modules in the ChatModules folder of the Chat service should return a function that is called with the ChatService parameter.

1 Like

Hi! How would i setup my game so that as soon as the player joins the game they are muted, like to diable the chat for EVERYONE, so they can see auto messages I set up but not be able to type in chat. I setup the auto messages to send, but how do I make it so nobody can type in chat? I figured it would have something to do with the mute chat service.