How to manipulate chat (mute players) via script

how would I mute a player until they reach a certain stats for ex time played

Muting a player is as simple as using the Property AudioDeviceInput.Muted.

you’d need to check if a player reaches a certain stat (im assuming a leaderstat in this scenario) and then mute them.

Here’s a simple stat code setup to your use case:

local Players = game:GetService("Players")

local valueToMeet = 0 -- This will be the value that will determine whether the player should be muted or not

Players.PlayerAdded:Connect(function(player: Player)

   local audioInput: AudioDeviceInput = player:WaitForChild("AudioDeviceInput") -- We will use this to mute the player using AudioDeviceInput's muted property
   local ls ="Folder")
   ls.Name = "leaderstats"
   ls.Parent = player

   local stat ="IntValue") -- set this to whatever type of stat you want
   stat.Value = nil -- Default Value
   stat.Parent = ls   


The script above creates a leaderstats folder, parents it to the player, and then a stat folder which parents to leaderstats.

From there, you can check if the stat meets a condition, which in this case if they reach a certain value.

This can be done with detecting if the stat’s value property has changed and using an if statement to check if its a single value.

We will use Changed Event to detect when the stat’s value changes. The Changed event passes the new value of the stat, which we can use to check if the new stat meets the value you set it to.

 stat.Changed:Connect(function(newValue) -- Event that detects when the stat value has changed
         if stat == valueToMeet then
              audioInput.Muted = true

I hope I helped. Let me know if you run into any problems or if you have any questions :slightly_smiling_face:

1 Like

Is this instance created in the player object or is it a player property? I am asking this cause I never saw a audiodeviceinput instance in the player object

That’s why we use WaitForChild as it’ll yield until AudioDeviceInput is found under the player which, from what I understand, happens when the player joins.

Could you link me the wiki for this bc this AudioDeviceInput is completely new to me

Sure. Here you go:

Here’s a link to the muted property:

Would this work for the chat as well?

Nope. You’d need to use TextChatService in that case. Below the code from script made by a Roblox Staff Member that contains a function you can use the mute the player.

The script below mutes any “speakers” in chat by checking if the speaker’s UserID matches the User ID of the userId provided. In your case, you’d pass player.UserId as the argument for muteUserId when checking if the stat meets a value from the script I provided earlier.

local TextChatService = game:GetService("TextChatService")

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

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

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.