Hiding chats from a textchatservice channel

Tried it:

TextChatService:WaitForChild("TextChannels"):WaitForChild("Logs").OnIncomingMessage = function(message)
	local source = message.TextSource
	if source then
		if source:IsA("Player") then
			message:Destroy()
		end
	end
end

Nothing happened.

Did I get the textsource wrong?

1 Like

Read. The. Documentation. Please.

1 Like

I did. The documentation isn’t going to help me if something is going wrong.

At least provide some code I could use.

1 Like

You are not supposed to destroy anything.

“Can only be implemented on the client.”

“Called when TextChannel is receiving an incoming message”

“If this callback returns a TextChatMessageProperties, those properties are merged with the TextChatMessage parameter to create a new TextChatMessage.”

Don’t return anything instead so the incoming message is canceled

1 Like

Thanks for the information I didn’t already know.

I said provide some code. If you aren’t going to do that, please stop helping me.

1 Like

I have a new script now from trialing a little bit.

local logsChannel = TextChatService:WaitForChild("TextChannels"):WaitForChild("Logs")

logsChannel.OnIncomingMessage = function(message)
	local properties = Instance.new("TextChatMessageProperties")
	properties.Text = message.Text

	if message.TextSource then
		local sourcePlayer = Players:GetPlayerByUserId(message.TextSource.UserId)
		if sourcePlayer then
			return nil
		end
	end

	return properties
end
1 Like

I just read through the documentation (that the other guy sent) and TextSource is the user’s name and information on things like their permission to the channel, etc.

TextSource is the data that represents a speaker in a TextChannel.

I am attempting to figure it out, please have patience.

1 Like

I’m not sure you can have a TextSource WITHOUT a user.

You can’t do “if source:IsA(“Player”)” because TextSource ISN’T a player, it’s a TextSource.

The TextSource’s name is going to be the DisplayName of whatever player it is for, the TextSource has this information from TextSource.UserID.

That was my old code:

I changed some stuff around.

Is that code integrated with the rest of the code in the initial post?

No. This is client sided now. The one before has had this part taken out:

And put in a client sided script:

local logsChannel = TextChatService:WaitForChild("TextChannels"):WaitForChild("Logs")

logsChannel.OnIncomingMessage = function(message)
	local properties = Instance.new("TextChatMessageProperties")
	properties.Text = message.Text

	if message.TextSource then
		local sourcePlayer = Players:GetPlayerByUserId(message.TextSource.UserId)
		if sourcePlayer then
			return nil
		end
	end

	return properties
end

Can you explain the issue again? Or if it has changed at all, what is it now?

Basically, there is no errors, but it won’t delete any messages incoming from players on the Logs text channel.

Where is it trying to remove messages in the new code?

Honestly, I’m more experienced with legacy chat service, that’s why I’m messed up here.

Is the “return nil” supposed to delete the message??

And I JUST started messing around with and learning TextChatService (or any chat in general) the other day.

No idea to be honest, it supposed to just stop it from sending?

lmao so we’re on the same page

1 Like

I have debugged this further and still no trace of deletion shown:

local logsChannel = TextChatService:WaitForChild("TextChannels"):WaitForChild("Logs")

logsChannel.OnIncomingMessage = function(message)
	print("OnIncomingMessage triggered")
	local properties = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		print("Message has TextSource")
		local player = Players:GetPlayerByUserId(message.TextSource.UserId)
		if player then
			print("Message from player: " .. player.Name)
			properties.Text = ""
			print("Message hidden")
			return properties
		else
			print("Message from non-player or unknown user")
		end
	else
		print("Message has no TextSource")
	end

	print("Allowing message to pass through")
	properties.Text = message.Text
	return properties
end

Prints:

  16:34:46.424  OnIncomingMessage triggered  -  Client - ChannelsManager:34
  16:34:46.424  Message has TextSource  -  Client - ChannelsManager:38
  16:34:46.424  Message from player: TeamDreams123 -  Client - ChannelsManager:41
  16:34:46.424  Message hidden  -  Client - ChannelsManager:43
  16:34:46.504  OnIncomingMessage triggered  -  Client - ChannelsManager:34
  16:34:46.504  Message has TextSource  -  Client - ChannelsManager:38
  16:34:46.504  Message from player: TeamDreams123 -  Client - ChannelsManager:41
  16:34:46.504  Message hidden  -  Client - ChannelsManager:43

Also I have no idea why the prints happen twice.

Nothing I have tried is working. I need someone else to help me with this (preferably someone who is experienced with TextChatService)

This is becoming a massive error for our game. Needing urgent help now.