Silencing (muting) an player

How would I make it so this script only works if the text inside of the TextBox is equal to the player’s name?

local Players = game.Players
local LocalPlayer = Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ModerationPanel = script.Parent.Parent.Parent
local UsernameBox = ModerationPanel.Username
local Button = script.Parent
local SilenceManager = ReplicatedStorage.SilenceManager
local SilencePlayer = SilenceManager:WaitForChild("SilencePlayer")
local NotifyPlayer = SilenceManager:WaitForChild("NotifyPlayer")

local Group = 13791384
local AllowedRank = 15

game.Players.PlayerAdded:Connect(function(Player)
	if Player:GetRankInGroup(Group) >= AllowedRank then
		Button.MouseButton1Click:Connect(function()
			SilencePlayer:FireClient()
			NotifyPlayer:FireClient(Player, "Panel", "The player has been muted.")
		end)
	end
end)
1 Like

Just check the text on the button.

local Players = game.Players
local LocalPlayer = Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ModerationPanel = script.Parent.Parent.Parent
local UsernameBox = ModerationPanel.Username
local Button = script.Parent
local SilenceManager = ReplicatedStorage.SilenceManager
local SilencePlayer = SilenceManager:WaitForChild("SilencePlayer")
local NotifyPlayer = SilenceManager:WaitForChild("NotifyPlayer")

local Group = 13791384
local AllowedRank = 15

game.Players.PlayerAdded:Connect(function(Player)
	if Player:GetRankInGroup(Group) >= AllowedRank then
		Button.MouseButton1Click:Connect(function()
			if Player.Name ~= Button.Text then
				return
			end
			
			SilencePlayer:FireClient()
			NotifyPlayer:FireClient(Player, "Panel", "The player has been muted.")
		end)
	end
end)
1 Like

I tried your script but it did not work.

1 Like

Oh wait, I put the wrong button, try this:

local Players = game.Players
local LocalPlayer = Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ModerationPanel = script.Parent.Parent.Parent
local UsernameBox = ModerationPanel.Username
local Button = script.Parent
local SilenceManager = ReplicatedStorage.SilenceManager
local SilencePlayer = SilenceManager:WaitForChild("SilencePlayer")
local NotifyPlayer = SilenceManager:WaitForChild("NotifyPlayer")

local Group = 13791384
local AllowedRank = 15

game.Players.PlayerAdded:Connect(function(Player)
	if Player:GetRankInGroup(Group) >= AllowedRank then
		Button.MouseButton1Click:Connect(function()
			if Player.Name ~= UsernameBox.Text then
				return
			end

			SilencePlayer:FireClient()
			NotifyPlayer:FireClient(Player, "Panel", "The player has been muted.")
		end)
	end
end)
1 Like

I’ve tried that as well, does it have anything to do with 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 Reason = Panel.UI.ModerationPanel.SilenceReason

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()
	Notification("Muted", "You have been silenced by an staff member for"..Reason.Text..". 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)

The script above is inside of a LocalScript and the other one is inside of a ServerScript.

2 Likes

@Katrist So is anything inside of that causing the script not to work?

2 Likes

That script seems alright, it’s just the way you’re handling the UI functions.

Usually you would have a remote event, and on the client, when the button is pressed, you would fire that to the server and handle it there. Yours however is different, because you just connected the function on the server which may cause bugs later down the line. I’ll try to fix it though.

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ModerationPanel = script.Parent.Parent.Parent
local UsernameBox = ModerationPanel.Username
local Button = script.Parent
local LocalPlayer = Button:FindFirstAncestorWhichIsA("Player")
local SilenceManager = ReplicatedStorage.SilenceManager
local SilencePlayer = SilenceManager:WaitForChild("SilencePlayer")
local NotifyPlayer = SilenceManager:WaitForChild("NotifyPlayer")

local Group = 13791384
local AllowedRank = 15

if LocalPlayer:GetRankInGroup(Group) >= AllowedRank then
	Button.MouseButton1Down:Connect(function()
		local playerFound = Players:FindFirstChild(UsernameBox.Text)
		
		if not playerFound then
			return
		end
		
		SilencePlayer:FireClient(playerFound)
		NotifyPlayer:FireClient(playerFound, "Panel", "The player has been muted.")
	end)
end
2 Likes

Well I used this tutorial and just edited things.

How to make an Mute Command

Also the script didn’t work again.

2 Likes

Yea, that’s the problem. In the video, he’s making a mute command based on an event that is already sent to the server. You however are connecting something that’s supposed to be on the client, to the server which causes a lot of problems. Try to change that mute button into a remote event and see if it works.

1 Like

How would I do that though that’s the thing.

1 Like

Show me your explorer.

1 Like

Okay here is the images.

image
image

1 Like

Switch that script under Silence into a LocalScript, and paste this inside:

--//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

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

Add a script in ServerScriptService and paste this inside:

--//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)
	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)
	NotifyPlayer:FireClient(player, "Panel", "The player has been muted.")
end)

Do I add an RemoteEvent named RequestSilence or?

1 Like

Yes, sorry I forgot to mention that. Add it into SilenceManager folder in ReplicatedStorage.

1 Like

Okay, I will go ahead and try the script now.

1 Like

It didn’t work, do you think it has something to do with “player” and “playerNameToSilence”?

1 Like

Wait what about this script, it’s a LocalScript inside of StarterGUI.

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 Reason = Panel.UI.ModerationPanel.SilenceReason

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()
	Notification("Muted", "You have been silenced by an staff member for"..Reason.Text..". 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

Could you show your explorer again?

1 Like

image
image

1 Like