TextChatService.OnIncomingMessage not firing?

I have this script

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local dev_ids = {1, 2, 3}
TextChatService.OnIncomingMessage = function(message: TextChatMessage)
	local props = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		local player = Players:GetPlayerByUserId(message.TextSource.UserId)

		if player then
			if table.find(dev_ids,player.UserId) then
				props.PrefixText = "<font color='#eeff00'>[🛠️Developer]</font> " .. message.PrefixText
			end
		end
	end

	return props	
end

based on the VIP tag example from this post
And I’ve added print statements to print after OnIncomingMessage is fired but it’s never printing that despite messages being sent. my ChatVersion is set to TextChatService. No clue what’s going on

1 Like

Where in the script did you place the print message that isn’t working? Also, where is your script located?

2 Likes

line right after OnIncomingMessage

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local dev_ids = {1, 2, 3} -- Add all developer IDs to this array
TextChatService.OnIncomingMessage = function(message: TextChatMessage)
	print("test")
	local props = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		local player = Players:GetPlayerByUserId(message.TextSource.UserId)

		if player then

			if table.find(dev_ids,player.UserId) then
				props.PrefixText = "<font color='#eeff00'>[🛠️Developer]</font> " .. message.PrefixText
			end
		end
	end

	return props	
end

1 Like

I added a print message there, and the print message displayed perfectly. Where is your script located?

2 Likes

It’s placed in StarterPlayerScripts

1 Like

I added print statements after each of the if statements, and they print all the way to the table.find if statement, where it stops. Mine is also located in StarterPlayerScripts.

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local dev_ids = {1, 2, 3}
TextChatService.OnIncomingMessage = function(message: TextChatMessage)
	print("Message found")
	local props = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		print("message.TextSource found")
		local player = Players:GetPlayerByUserId(message.TextSource.UserId)

		if player then
			print("Player found")
			if table.find(dev_ids,player.UserId) then
				print("Table found")
				props.Text = "<font color='#eeff00'>[🛠️Developer]</font> " .. message.PrefixText
			end
		end
	end

	return props	
end
2 Likes

Printing nothing :frowning:

char limit

You need to replace 1, 2, 3 in the dev_ids to be the actual player.UserId of the player. After I did that, it worked perfectly. Here is my updated script (hopefully this works for you):

local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local dev_ids = {1206175753} -- replace this number with your players UserId
TextChatService.OnIncomingMessage = function(message: TextChatMessage)
	print("Message found")
	local props = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		print("message.TextSource found")
		local player = Players:GetPlayerByUserId(message.TextSource.UserId)

		if player then
			print("Player found")
			print(player.UserId)
			if table.find(dev_ids, player.UserId) then
				print("Table found")
				props.Text = "<font color='#eeff00'>[🛠️Developer]</font> " .. message.PrefixText
			end
		end
	end

	return props	
end
2 Likes

Here’s the really weird part. It’s working on a blank baseplate

I have no clue why it doesn’t work under my actual game

1 Like

In case you are wondering, I added the print(player.UserId) to get my UserId to enter in where I replace 1, 2, 3

2 Likes

Are there any other scripts in your game that mess with the chat configuration, such as changing chat color, chat titles, etc?

2 Likes

Found it out - you cannot handle OnIncomingMessage more than once

roblox should REALLY have it error out if you’re calling it twice
I had another script that can create [System] messages

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