Text Channel Switching Error

For some reason whenever I switch textchannels, TextSource starts returning nil

I am making a system where you can run a command to have a private chat in a private channel

Server-side code:

local TextChatService = game:GetService("TextChatService")
local Prefix = "!" 
local ChangeChat = game.ReplicatedStorage.ChangeChat
local OwnerTagged = {REDACTED}

game.Players.PlayerAdded:Connect(function(plr)
	print(TextChatService.CustomChannels.Admins:AddUserAsync(plr.UserId))
	plr.Chatted:Connect(function(msg)
		if table.find(OwnerTagged, plr.UserId) then
				local loweredString = string.lower(msg)
				local args = string.split(loweredString," ")
				if args[1] == Prefix.. "admin" or args[1] == Prefix.. "admins" then
					ChangeChat:FireClient(plr, "Admins")
				end
			end
		end)
	end)

LocalScript:

local TextChatService = game:GetService("TextChatService")
local Properties = Instance.new("TextChatMessageProperties")
local BadgeService = game:GetService("BadgeService")
local ChatBar = TextChatService:WaitForChild("ChatInputBarConfiguration")

local OwnerTagged = {REDACTED}
local Tester

local ChatBar = TextChatService:WaitForChild("ChatInputBarConfiguration")
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("ChangeChat")

local AdminOrNot = true

Remote.OnClientEvent:Connect(function(newchat)
	local Channel = AdminOrNot and TextChatService.CustomChannels[newchat] or TextChatService.TextChannels.RBXGeneral
	print(Channel)
	ChatBar.TargetTextChannel = Channel

	if Channel == TextChatService.TextChannels.RBXGeneral then
		Channel:DisplaySystemMessage("You're now chatting in Default Chat.")
	elseif Channel == TextChatService.CustomChannels.Admins then
		Channel:DisplaySystemMessage("You're now chatting in Admins.")
	end
	AdminOrNot = not AdminOrNot
	print(AdminOrNot)
end)

TextChatService.OnIncomingMessage = function(Message: TextChatMessage)
	
	print(Message.TextSource)
	
	if Message.TextChannel ~= TextChatService.TextChannels.RBXGeneral then
		if TextChatService.TextChannels:FindFirstChild(Message.TextChannel.Name) then
			return
		end
		local ChannelColor = Message.TextChannel:GetAttribute("Color") or {R = 1, G = 1, B = 1}
		Properties.PrefixText = (string.format("<font color='rgb(%s, %s, %s)'>[%s]%s %s</font>",
			math.round(ChannelColor.R * 255),
			math.round(ChannelColor.G * 255),
			math.round(ChannelColor.B * 255),
			Message.TextChannel.Name,
			"testing",
			Message.PrefixText
			)
		)

	else
		
		
	if Message.TextSource then
		local Player = game:GetService("Players"):GetPlayerByUserId(Message.TextSource.UserId)
		local REDACTEDRole= nil
		
		if Player:IsInGroup(REDACTED) then
			REDACTEDRole = Player:GetRoleInGroup(REDACTED)
		end
		
		print(Message.TextChannel)
		
		if table.find(OwnerTagged, Player.UserId) then
			Properties.PrefixText = "<font color='rgb(255, 255, 0)'>[OWNER] ".. Message.PrefixText.. "</font>"
		elseif YimelloRole == "Admins" or Player.UserId == REDACTED then
			Properties.PrefixText = "<font color='rgb(255, 0, 0)'>[ADMIN] ".. Message.PrefixText.. "</font>"
		elseif REDACTEDRole == "Testers" then
			Properties.PrefixText = "<font color='rgb(0, 255, 0)'>[TESTER] ".. Message.PrefixText.. "</font>"
		elseif BadgeService:UserHasBadgeAsync(Player.UserId, REDACTED) then
			Properties.PrefixText = "<font color='rgb(0, 255, 238)'>[OG] ".. Message.PrefixText.. "</font>"
		elseif Player:IsInGroup(REDACTED) then
			Properties.PrefixText = "<font color='rgb(150, 150, 0)'>[GROUP MEMBER] ".. "</font>".. Message.PrefixText
		end
	end
end
	if TextChatService.TextChannels:FindFirstChild(Message.TextChannel.Name) then return Properties end
	if Message.TextSource then
	local ChannelColor = Message.TextChannel:GetAttribute("Color") or {R = 1, G = 1, B = 1}
	Properties.PrefixText = (string.format("<font color='rgb(%s, %s, %s)'>[%s]%s %s</font>",
		math.round(ChannelColor.R * 255),
		math.round(ChannelColor.G * 255),
		math.round(ChannelColor.B * 255),
		Message.TextChannel.Name,
		"testing",
		Message.PrefixText
		)
	)
	end
	return Properties
end
  • I know it looks in-efficient. That is because my brain is broken and I’ve tried just about everything I can think of
  • Everything is redacted because I am embarrassed for everyone involved for me having this problem

Edit: just like my last post, it was something really stupid I fixed on my own 10 minutes after I made the post despite trying to fix it for hours before the post and failing

Sorry for wasting everyone’s time

1 Like

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