Mute-Command only refreshes the Chat

Hi! So I’m trying to make a Mute-Command but for some reason it’s only refreshing the chat.
Code:

if splits[1]:lower() == HRCommands["Mute-Command"] and plr.leaderstats.Rank.Value >= 7 then
			--Find the player 
			for i,v in next, game.Players:GetChildren() do
				if v.Name:sub(1, name:len()):lower() == name:lower() then
					--v is the correct player
					local backPack = v.Backpack
					local MuteScripts = ReplicatedStorage.Mute
					local MuteScript = MuteScripts.MuteScript
					local unMuteScript = MuteScripts.UnMuteScript
					local timeToMute = tonumber(splits[2])
					local function mutePlayer(backPack)
						--Clone the script into his backPack
						local clone = MuteScript:Clone()
						clone.Parent = backPack
						wait(timeToMute)
						clone:Destroy()
						local newClone = unMuteScript:Clone()
						newClone.Parent = backPack
						newClone:Destroy()
					end
					local wrappedFunction = coroutine.wrap(mutePlayer)
					local fireFunction = wrappedFunction(backPack)
				end
			end
		end

Basically the MuteScript and the UnMuteScript:
MuteScript:

game:GetService("StarterGui"):SetCoreGuiEnabled("Chat", false)

UnMuteScript:

game:GetService("StarterGui"):SetCoreGuiEnabled("Chat", true)

Thank you!

2 Likes

I’m not sure why you would need to put it in Seperate script. Thats also hiding the chat not muting it.

To actually mute it you need to use ChatService.

2 Likes

I thought by disabling their chat, they would not be able to chat anymore, that makes sense, I guess.

Can you tell me a ChatService function that can mute someone, please?

1 Like

Also, I’m putting it in seperate scripts because I’m pretty sure that I can’t disable their CoreGui through the server, Remote Functions/Events would be an option, kinda forgot about them. :laughing:

1 Like

If you are not sure how ChatService works, its a module inserted into the game.

local ChatService = require(
 game:GetService("ServerScriptService")
 :WaitForChild("ChatServiceRunner")
 :WaitForChild("ChatService")
)

To mute the Chat u would get the All chat channel then mute all the speakers in it.
Also ChatService is on the server

-- pseudo code
on MuteCommand do
  local Channel = ChatService:GetChannel("All") -- We get the All channel.
  for _, speakerName in ipairs(Channel:GetSpeakerList() do -- loop trough all speakers
    Channel:MuteSpeaker(speakerName) -- Mute the speaker
  end
end
5 Likes

Oh. So the Speaker is the player, correct?

1 Like

No, it is the name of the player

2 Likes

Every player has a Speaker. but u can create custom speakers or Bots. Using ChatService:AddSpeaker(name)

3 Likes

So if you mute the speaker of a player, he won’t be able to chat anymore?
@Luka_Gaming07 , @sjr04