MuteGui: Make specific player(s) locally invisible & mute chats [to evade trolls], but having issue with muting chats

1. What do you want to achieve? Keep it simple and clear!
I have screengui that opens up and lists all the players actively in the game, each with a button next to their name. When you click the button, it turns that specific player invisible, and WOULD mute their chats so that the local player does not see them. The purpose is to mute trolls by removing them visually+chats from the local player’s game. I would like the mute portion to function identically to the /mute command, but worked into this gui button so it’s easier for players to evade trolls.

2. What is the issue? Include screenshots / videos if possible!
The issue is that I can’t get the ‘muting’ chat portion to work within the script. When I click the buttons, the character does disappear as intended, but their chat is still able to be seen by the local player that muted them.

3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I used ai bots to help me write the script and both bots have gotten to the point of running in circles. I have also referenced several dev posts related to muting chats (commands, admin panels, etc) and tried to apply it locally and through the button to no avail.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

SCRIPT THAT IS INSIDE BUTTON [I UNDERSTAND AND CAN READ BASIC SCRIPTING LINGO BUT I CAN’T EFFICIENTLY WRITE SCRIPT MYSELF]. I ALSO HAVE A SCRIPT THAT PARENTS THE PLAYERLIST GUI, AND IT WORKS PERFECTLY, SO I’M JUST POSTING THE BUTTON FUNCTION SCRIPT:

local players = game:GetService(“Players”)
local player = players.LocalPlayer or players.PlayerAdded:Wait()
local button = script.Parent

– Function to toggle player transparency and hide chat for a specific player
local function togglePlayerVisibility(targetPlayer)
local character = targetPlayer.Character
if character then
for _, part in ipairs(character:GetDescendants()) do
if part:IsA(“BasePart”) or part:IsA(“Decal”) then
if part.Name ~= “HumanoidRootPart” then
part.Transparency = (part.Transparency == 1) and 0 or 1 – Toggle part visibility
end
end
end
end
end

local TextChatService = game:GetService(“TextChatService”)

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 pairs(TextChatService:GetDescendants()) do
	if child:IsA("TextSource") then
		if child.UserId == mutedUserId then
			child.CanSend = false
		end
	end
end

end

– Function to handle button click event for a specific player
button.MouseButton1Click:Connect(function()
– Get the associated player of the button using its name/label
local targetUserId = tonumber(button.Name) – Extract the player ID from the button’s name
local targetPlayer = players:GetPlayerByUserId(targetUserId)

if targetPlayer then
	togglePlayerVisibility(targetPlayer)
	muteUserId(targetUserId)  -- Mute the player associated with the button's UserID
end

end)