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:
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.
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