Need help with a mute system as my code doesnt work

I Want to make it so the player is muted when the remote event is fired but it doesnt work and doesnt provide a error.
robloxapp-20231218-2124365.wmv (661.7 KB)

events.Mute.OnServerEvent:Connect(function(plr,PlayerToMute)
	if game.TextChatService.ChatVersion == Enum.ChatVersion.LegacyChatService then
		local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild ("ChatService"))
		local channel = ChatService:GetChannel("ALL")

		channel:MuteSpeaker()

	elseif game.TextChatService.ChatVersion == Enum.ChatVersion.TextChatService then
		local TextChatService = game:GetService("TextChatService")

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

			for _, child in TextChatService:GetDescendants() do
				if child:IsA("TextSource") then
					if child.UserId == mutedUserId then
						child.CanSend = false
					end
				end
			end
		end
		muteUserId(PlayerToMute.UserId)
	end	
end)
Summary

The mute system doesnt mute the player and doesnt give any sort of error not even a warning, the code was found on the devforum.

1 Like

Alright i have to go now so i will reply to the post left.

I haven’t used ChatService before, but I think the problem might lie within line 8.

I’m not sure why the channel is muted and immediately unmuted, so try removing the line which unmutes.

that isnt an issue but i am using TextChatService in the video.

the reason why it isnt a issue is because it was for testing.

@ThatOneNoobOnTheTeam When i switch the chat version i get this error from the roblox chat service

  16:33:09.285  ServerScriptService.ChatServiceRunner.ChatService:171: attempt to index nil with 'lower'  -  Server - ChatService:171

- :warning: Important Notes :


• LegacyChatVersion mutes speakers by displaying text that their muted everytime they attempt to chat. Using ChatService you can mute someone using

ChatService:GetChannel(“ALL”):MuteSpeaker(“PLAYER NAME”)

‎
• TextChatService mutes speakers by allowing the speaker to talk but not display on any other client without warning.

TextChatService.TextChannels.RBXGeneral[“PLAYER NAME”].CanSend = false

‎


----- || SERVICES || -----
local ServerScriptService = game:GetService("ServerScriptService")
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")



----- || VARIABLES || -----
local PlayerStorage = {}

local MuteSignal = events.Mute.OnServerEvent
local UnMuteSignal = events.Unmute.OnServerEvent

local ChatVersion = TextChatService.ChatVersion
local ChatService = ChatVersion == Enum.ChatVersion.LegacyChatService and require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService")) or nil


----- || METHODS || -----
function MuteSpeaker( player : Player, target : Player )
	PlayerStorage[target.UserId] = false
	
	if ChatVersion == Enum.ChatVersion.TextChatService then return end
	ChatService:GetChannel("ALL"):MuteSpeaker(player.Name)
end

function UnmuteSpeaker( player : Player, target : Player )
	PlayerStorage[target.UserId] = false
	
	if ChatVersion == Enum.ChatVersion.TextChatService then return end
	ChatService:GetChannel("ALL"):UnmuteSpeaker(player.Name)
end


function PlayerAdded( player : Player )
	if PlayerStorage[player.UserId] then return end
	PlayerStorage[player.UserId] = true
end

function PlayerRemoving( player : Player )
	PlayerStorage[player.UserId] = nil
end



----- || MAIN SCRIPT || -----
MuteSignal:Connect(MuteSpeaker)
UnMuteSignal:Connect(UnMuteSignal)

for _, player in Players:GetPlayers() do PlayerAdded(player) end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(PlayerRemoving)

Background = coroutine.wrap(function()
	while task.wait(1) do
		if ChatVersion == Enum.ChatVersion.LegacyChatService then break end

		for _, speaker in TextChatService:GetDescendants() do
			if not speaker:IsA("TextSource") then continue end

			speaker.CanSend = PlayerStorage[speaker.UserId]
		end
	end
end)()

It seems that it doesnt work i have been given this error

  21:26:25.292  ServerScriptService.MainModule.MainHandler:104: attempt to index nil with 'GetChannel'  -  Server - MainHandler:104

I just realized I flipped my signs, try using it now.

1 Like

Thanks Don it seems that you always know what to do … ok thats not true but you know what i mean.

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