Roblox Tutorial - How to make a mute command source code

Notification Handler:

local ReplicatedStorage = game:GetService("ReplicatedStorage").MuteCommandRoblox
local StarterGui = game:GetService("StarterGui")

local MuteUser = ReplicatedStorage:WaitForChild("MuteUser")
local SomethingWentWrong = ReplicatedStorage:WaitForChild("WentWrong")

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

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

MuteUser.OnClientEvent:Connect(function(Status)
	if Status == true then
		Notification("MUTED", "You were muted, you can no longer speak in chat!")
		ChatEnabled(false)
	else
		Notification("UN-MUTED", "You can now speak in chat!")
		ChatEnabled(true)
	end
end)

SomethingWentWrong.OnClientEvent:Connect(function(Title, Msg)
	Notification(Title, Msg)
end)

Mute command handler:

local ReplicatedStorage = game:GetService("ReplicatedStorage").MuteCommandRoblox

local MuteUser = ReplicatedStorage:WaitForChild("MuteUser")
local SomethingWentWrong = ReplicatedStorage:WaitForChild("WentWrong")

local GroupId = 10392184
local MinRank = 3

local function PlayerInstance(PlayerName)
	if game.Players:FindFirstChild(PlayerName)  then
		return game.Players:FindFirstChild(PlayerName)
	else
		return false
	end
end

game.Players.PlayerAdded:Connect(function(player)
	if player:GetRankInGroup(GroupId) >= MinRank then
		player.Chatted:Connect(function(Msg)
			local SplitMesssage = string.split(Msg, " ")
			local PlayerInstance = PlayerInstance(SplitMesssage[2])
			
			if PlayerInstance == false then
				SomethingWentWrong:FireClient(player, "Uh-oh", "We couldn't find the player you wanted!")
			else
				if SplitMesssage[1] == "!mute" then
					MuteUser:FireClient(PlayerInstance, true)
					SomethingWentWrong:FireClient(player, "SUCCESS", "We muted the player!")
				else if SplitMesssage[1] == "!unmute" then
						MuteUser:FireClient(PlayerInstance, false)
						SomethingWentWrong:FireClient(player, "SUCCESS", "We un-muted the player!")
					end
				end
			end
		end)
	end
end)

Have any issues?

Create a new topic in #scripting-support!

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