OnIncomingMessage is a callback member of TextChatService

Everytime I try doing this code, it gives me that error.
Here is my local script placed in StarterGui

local tcs = game:GetService("TextChatService")
tcs.OnIncomingMessage:Connect(function(message:TextChatMessage)
	if not message.TextSource then return end
	local player = game.Players:GetPlayerByUserId(message.TextSource.UserId)
	if not player then return end
	local properties = Instance.new("TextChatMessageProperties")
	properties.PrefixText = tostring("<font color = \"rgb(230, 0, 0)\">["..player.Name..utf8.char(0xE000).."]: </font>")
	return properties
end)

That means it’s a write-only property whose value is a function, not an event. So you’ll have to set a function as the value of this property.

local tcs = game:GetService("TextChatService")
tcs.OnIncomingMessage = function(message:TextChatMessage)
	if not message.TextSource then return end
	local player = game.Players:GetPlayerByUserId(message.TextSource.UserId)
	if not player then return end
	local properties = Instance.new("TextChatMessageProperties")
	properties.PrefixText = tostring("<font color = \"rgb(230, 0, 0)\">["..player.Name..utf8.char(0xE000).."]: </font>")
	return properties
end

If you need to do many things when a message is sent, you’ll have to combine them all into one function.

3 Likes

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