Silencing (muting) an player

Switch your server script (SilenceHandler) to this:

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local SilenceManager = ReplicatedStorage.SilenceManager
local RequestSilence = SilenceManager:WaitForChild("RequestSilence")
local SilencePlayer = SilenceManager:WaitForChild("SilencePlayer")
local NotifyPlayer = SilenceManager:WaitForChild("NotifyPlayer")

--//Controls
local Group = 13791384
local AllowedRank = 15

--//Functions
RequestSilence.OnServerEvent:Connect(function(player, playerNameToSilence)
	print(playerNameToSilence)
	if not playerNameToSilence or type(playerNameToSilence) ~= "string" or player:GetRankInGroup(Group) < AllowedRank then
		return
	end
	
	print(playerNameToSilence)
	
	local playerToSilence = Players:FindFirstChild(playerNameToSilence)
	
	if not playerToSilence then
		return
	end
	
	print(playerToSilence)
	SilencePlayer:FireClient(playerToSilence)
	NotifyPlayer:FireClient(player, "Panel", "The player has been muted.")
end)

Tell me what it prints.

1 Like
local textBox = -- Path To TextBox

local textBoxTextIsPlayerName = false

for _, player in game.Players:GetPlayers() do
	if textBox.Text ~= player.Name then continue end
	textBoxTextIsPlayerName = true
	break
end

if textBoxTextIsPlayerName then
	-- Run your code
end
2 Likes

It worked, thank you. Also for the “Player has been muted” notification does that only notify the person who opened the panel and muted the targeted player?

1 Like

Thanks I will save this just in case. :smile:

1 Like

It notifies the person who muted them.

1 Like

I want that notification to only appear to the person who manually muted them on the panel. Also for this script;

	Notification("Muted", "You have been silenced by an staff member for"..Reason.Text..". You can no longer communicate with others inside the chat.")

The reason text isn’t displaying, how do I fix that?

1 Like

By the way how can I make the script return and end if the chat is already disabled?

1 Like

Change your Handler to this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
local Panel = StarterGui.Panel
local SilenceManager = ReplicatedStorage.SilenceManager
local SilencePlayer = SilenceManager:WaitForChild("SilencePlayer")
local UnsilencePlayer = SilenceManager:WaitForChild("UnsilencePlayer")
local NotifyPlayer = SilenceManager:WaitForChild("NotifyPlayer")

local function ChatEnabled(Enabled)
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, Enabled)
end

local function Notification(Title, Text)
	StarterGui:SetCore("SendNotification", {
		Title = Title,
		Text = Text
	})
end

SilencePlayer.OnClientEvent:Connect(function(reason)
	Notification("Muted", "You have been silenced by an staff member for "..reason..". You can no longer communicate with others inside the chat.")
	ChatEnabled(false)
end)

UnsilencePlayer.OnClientEvent:Connect(function()
	Notification("Un-muted", "You have been un-silenced, you can now communicate with others within the chat.")
	ChatEnabled(true)
end)

NotifyPlayer.OnClientEvent:Connect(function(Title, Message)
	Notification(Title, Message)
end)

And your server code to this:

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local SilenceManager = ReplicatedStorage.SilenceManager
local RequestSilence = SilenceManager:WaitForChild("RequestSilence")
local SilencePlayer = SilenceManager:WaitForChild("SilencePlayer")
local NotifyPlayer = SilenceManager:WaitForChild("NotifyPlayer")

--//Controls
local Group = 13791384
local AllowedRank = 15

--//Functions
RequestSilence.OnServerEvent:Connect(function(player, playerNameToSilence, reason)
	if reason and type(reason) ~= "string" then
		return
	end
	
	if not playerNameToSilence or type(playerNameToSilence) ~= "string" or player:GetRankInGroup(Group) < AllowedRank then
		return
	end

	local playerToSilence = Players:FindFirstChild(playerNameToSilence)

	if not playerToSilence then
		return
	end

	SilencePlayer:FireClient(playerToSilence, reason)
	NotifyPlayer:FireClient(player, "Panel", "The player has been muted.")
end)

And that LocalScript at the start to this:

--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local SilenceManager = ReplicatedStorage.SilenceManager
local RequestSilence = SilenceManager:WaitForChild("RequestSilence")
local Button = script.Parent
local ModerationPanel = Button.Parent.Parent
local UsernameBox = ModerationPanel.Username
local SilenceReason = ModerationPanel.SilenceReason

--//Functions
Button.MouseButton1Down:Connect(function()
	RequestSilence:FireServer(UsernameBox.Text, SilenceReason.Text)
end)
1 Like

Thanks. If the player is already silenced how would I make it not go through?

1 Like

Change the handler to this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")
local Panel = StarterGui.Panel
local SilenceManager = ReplicatedStorage.SilenceManager
local SilencePlayer = SilenceManager:WaitForChild("SilencePlayer")
local UnsilencePlayer = SilenceManager:WaitForChild("UnsilencePlayer")
local NotifyPlayer = SilenceManager:WaitForChild("NotifyPlayer")

local function ChatEnabled(Enabled)
	StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, Enabled)
end

local function Notification(Title, Text)
	StarterGui:SetCore("SendNotification", {
		Title = Title,
		Text = Text
	})
end

SilencePlayer.OnClientEvent:Connect(function(reason)
	if StarterGui:GetCoreGuiEnabled(Enum.CoreGuiType.Chat) then
		return
	end
	
	Notification("Muted", "You have been silenced by an staff member for "..reason..". You can no longer communicate with others inside the chat.")
	ChatEnabled(false)
end)

UnsilencePlayer.OnClientEvent:Connect(function()
	Notification("Un-muted", "You have been un-silenced, you can now communicate with others within the chat.")
	ChatEnabled(true)
end)

NotifyPlayer.OnClientEvent:Connect(function(Title, Message)
	Notification(Title, Message)
end)
1 Like

Will do and also for the command to open/close it, I want to lock it to a group rank, how would I do it? (sorry for asking so much questions)

local Players = game.Players
local LocalPlayer = Players.LocalPlayer
local TextChatService = game:GetService("TextChatService")
local MainGUI = LocalPlayer.PlayerGui.Panel
local MainFrame = MainGUI.UI
local ModerationFrame = MainFrame.ModerationPanel
local PlayerFrame = MainFrame.PlayerPanel
local MenuButton = MainFrame.Menu
local ModerationButton = MainFrame.Moderation
local PlayerButton = MainFrame.Player
local WelcomeText = MainFrame.Welcome

TextChatService.SendingMessage:Connect(function(TextChatMessage)
	local Str = TextChatMessage.Text

	if (Str == ";openpanel") then 
		MainGUI.Enabled = true 
	elseif (Str == ";closepanel") then 
		MainGUI.Enabled = false 
	end
end)

Here:

local Players = game.Players
local LocalPlayer = Players.LocalPlayer
local TextChatService = game:GetService("TextChatService")
local MainGUI = LocalPlayer.PlayerGui.Panel
local MainFrame = MainGUI.UI
local ModerationFrame = MainFrame.ModerationPanel
local PlayerFrame = MainFrame.PlayerPanel
local MenuButton = MainFrame.Menu
local ModerationButton = MainFrame.Moderation
local PlayerButton = MainFrame.Player
local WelcomeText = MainFrame.Welcome

local groupId = 000000
local rankId = 000000

TextChatService.SendingMessage:Connect(function(TextChatMessage)
	if LocalPlayer:GetRankInGroup(groupId) < rankId then
		return
	end
	
	local Str = TextChatMessage.Text

	if (Str == ";openpanel") then 
		MainGUI.Enabled = true 
	elseif (Str == ";closepanel") then 
		MainGUI.Enabled = false 
	end
end)

If it works, please mark my reply as the solution.

This part,

	if StarterGui:GetCoreGuiEnabled(Enum.CoreGuiType.Chat) then
		return
	end

It makes the script not work properly meaning it doesn’t silence the player.

Oh wait, I forgot to change that to not.

Fixed code:

if not StarterGui:GetCoreGuiEnabled(Enum.CoreGuiType.Chat) then
	return
end

Thanks so much, I’ll try it now and by the way I marked your reply as an solution. If I have any more errors I’ll let you know and in the future can I message you for further assistance just in case?

Also does the “Panel”, “The player has been muted” only notify the player who manually muted them, I want it to be a success notification for the panel user.

Even though it doesn’t send the muted notification through for some reason I get the notification of “The player has been muted”. How would I make it not notify if the player is already muted?

local mutedPlayers = {}

-- set it so they appear as muted
mutedPlayers[player] = true

-- check somewhere before you send the remote

if mutedPlayers[player] then return end
1 Like

Do I add that in this script?

--//Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")

--//Variables
local SilenceManager = ReplicatedStorage.SilenceManager
local RequestSilence = SilenceManager:WaitForChild("RequestSilence")
local SilencePlayer = SilenceManager:WaitForChild("SilencePlayer")
local NotifyPlayer = SilenceManager:WaitForChild("NotifyPlayer")

--//Controls
local Group = 13791384
local AllowedRank = 15

--//Functions
RequestSilence.OnServerEvent:Connect(function(player, playerNameToSilence, reason)
	if reason and type(reason) ~= "string" then
		return
	end

	if not playerNameToSilence or type(playerNameToSilence) ~= "string" or player:GetRankInGroup(Group) < AllowedRank then
		return
	end

	local playerToSilence = Players:FindFirstChild(playerNameToSilence)

	if not playerToSilence then
		return
	end

	SilencePlayer:FireClient(playerToSilence, reason)
	NotifyPlayer:FireClient(player, "Panel", "The player has been successfully silenced.")
end)