Custom TextChannels in chat version TextChatService

how do I delete a player from a new channel when they change their team?

local Players = game:GetService("Players")
local TCS = game:GetService("TextChatService")

local allowedTeamsChannel1 = {
	["FBI"] = true,
	["Police"] = true,
}

local TeamChannel = Instance.new("TextChannel", TCS:WaitForChild("TextChannels"))
TeamChannel.Name = "agy agy"

function isPlayerInAllowedTeam(plr)
	local playerTeamName = plr.Team and plr.Team.Name
	return playerTeamName and allowedTeamsChannel1[playerTeamName] or false
end

function updatePlayerTeamChannel(plr)
	if isPlayerInAllowedTeam(plr) then
		TeamChannel:AddUserAsync(plr.UserId)
	end
end

function handlePlayerConnections(plr)
	updatePlayerTeamChannel(plr)
	plr:GetPropertyChangedSignal("Team"):Connect(function()
		updatePlayerTeamChannel(plr)
	end)
end

Players.PlayerAdded:Connect(function(plr)
	handlePlayerConnections(plr)
end)

for _, plr in ipairs(Players:GetPlayers()) do
	handlePlayerConnections(plr)
end

3 Likes

From looking around the documentation a bit:

You should be able to store the result of AddUserAsync, then call Destroy on it later on.

local TextSource = TeamChannel:AddUserAsync(plr.UserId) -- Adds the player
TextSource:Destroy() -- Removes the player.

If anything, I want to make a walkie-talkie.

1 Like