Help with chat mute button? (First post)

Hello everyone, I’m a new member and this is my first post. (Maybe it would be helpful also to tell me if this post is good or how should I improve it. I’ll be making like 10 posts because I’ve wanted to join the DevForum forever)

  1. What do you want to achieve? Keep it simple and clear!
    I want to make a chat mute button for my admin panel. It will stop the player from sending any messages but they should still be able to see the chat.

  2. What is the issue? Include screenshots / videos if possible!
    I literally have no idea how to.
    The way my admin panel works is you can select a person from a character list.

Code:

local button = script.Parent
local selected = script.Parent.Parent.Parent.playerscroll.IsClicked
local selectedName = script.Parent.Parent.Parent.playerscroll.SelectedName
local TextChatService = game:GetService("TextChatService")
local isOn = false
local player = game.Players.LocalPlayer
local isMuted = false

local function muteUserId(mutedUserId)
	-- listen for future TextSources
	TextChatService.DescendantAdded:Connect(function(child)
		if child:IsA("TextSource") then
			if child.UserId == mutedUserId then
				child.CanSend = false
			end
		end
	end)

	-- mute any current TextSources
	for _, child in TextChatService:GetDescendants() do
		if child:IsA("TextSource") then
			if child.UserId == mutedUserId then
				child.CanSend = false
			end
		end
	end
end

-- Function to toggle chat mute
local function toggleChatMute()
	if selected then	
		if selectedName ~= "" then
			if isMuted then
				isMuted = false
				button.label.Text = "Mute"
			else
				muteUserId(game.Players.LocalPlayer.UserId)
				isMuted = true
				button.label.Text = "Unmute"
			end
		end
	end
end

button.MouseButton1Click:Connect(toggleChatMute)

The selected and selected name variable are if a person has selected a player to take action against (ban, warn, mute, ect)

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried but for some reason most of the solutions didn’t work. More specifically, I looked at the only 2 posts that really tell you about this. The first one I looked at used the old chat system but this is the one i looked at.
4 Likes

Can I see what the GUI looks like in the Explorer tab?

Hey bro can I use your admin panel for my game once you get it fixed?

Idk, this is just a bit too simplistic to pass up for me. If I ban someone from a game, I don’t let them spectate the game. They just can’t get in the game at all after that. Granted this is just an example. Shouldn’t be too hard to implement. This only works on the player as others can use the chat icon.

local player = game:GetService("Players").LocalPlayer
local mutedUserId = 123456789

local ID = player.UserId
if  ID == mutedUserId then
	game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
end	
1 Like

image
the “playerscroll” is where the playerlist buttons are parented to

Unfortunately, as said in my original post i just want to stop the player from chatting but can still see the chat. I might do that if all else fails.

1 Like

ive decided after forever that this is the best solution

2 Likes

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