TextChatService.OnIncomingMessage Does not Work

I am working on a script that teleports players between different places of the same game.

This script worked until I made it so that chatting “/joinPC” was available to all players, and not just high ranks in a group.

The chat script also handles chat tags based on rank in said group.

However, since those changes, the chat script seems to have been broke, as seen with the following images:
image

As you can see, all that happens is it keeps returning “return message: Instance” and I have no idea why.

Here’s the code:

--!strict
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")

TextChatService.OnIncomingMessage = function(message: TextChatMessage)
	local props = Instance.new("TextChatMessageProperties")
	
	if message.TextSource then
		local player = Players:GetPlayerByUserId(message.TextSource.UserId)
		
		if message.Text:match("/joinPC") ~= nil then
			--if player:GetAttribute("highRank") == true then
				TeleportService:Teleport(16984680470)
			--end
		elseif message.Text:match("/joinMobile") ~= nil then
			if player:GetAttribute("highRank") == true then
				TeleportService:Teleport(15222475262)
			end
		end
		
		if player:GetAttribute("Dev") == true then
			props.PrefixText = "<font color='#fefaeb'>[DEV]</font> " .. message.PrefixText	
		elseif player:GetAttribute("Admin") == true then
			props.PrefixText = "<font color='#f53058'>[ADMIN]</font> " .. message.PrefixText		
		elseif player:GetAttribute("Mod") == true then
			props.PrefixText = "<font color='#f53058'>[MOD]</font> " .. message.PrefixText	
		elseif player:GetAttribute("VIP") == true then
			props.PrefixText = "<font color='#F5CD30'>[VIP]</font> " .. message.PrefixText
		elseif player.MembershipType == Enum.MembershipType.Premium then
			props.PrefixText = "<font color='#30f56b'>[PREMIUM]</font> " .. message.PrefixText		
		end
	end
	
	return props	
end

it is located in a local script in StarterPlayerScripts

1 Like

it’ll print “instance” because the type “TextChatMessage” is actually an object with some attributes like the Text, try to print message.Text at the begginning, this script hasn’t any problem

1 Like

Yes, but this didn’t happen until I commented out “if player:GetAttribute(“highRank”) == true then” and the following “end”

so if you add an if the script will broke?

I added the print statement you suggested, and it did not print what I tried chatting, it kept printing “return message: Instance”

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

TextChatService.OnIncomingMessage = function(message: TextChatMessage)
	local props = Instance.new("TextChatMessageProperties")
	if message.TextSource then
		local player = Players:GetPlayerByUserId(message.TextSource.UserId)
		
		
		print("text: ", message.Text)
		if message.Text:match("/joinPC") ~= nil then
			print("joinedPc")
		elseif message.Text:match("/joinMobile") ~= nil then
			print("JoinedMobile")
		end

		if player:GetAttribute("Dev") == true then
			props.PrefixText = "<font color='#fefaeb'>[DEV]</font> " .. message.PrefixText	
		elseif player:GetAttribute("Admin") == true then
			props.PrefixText = "<font color='#f53058'>[ADMIN]</font> " .. message.PrefixText		
		elseif player:GetAttribute("Mod") == true then
			props.PrefixText = "<font color='#f53058'>[MOD]</font> " .. message.PrefixText	
		elseif player:GetAttribute("VIP") == true then
			props.PrefixText = "<font color='#F5CD30'>[VIP]</font> " .. message.PrefixText
		elseif player.MembershipType == Enum.MembershipType.Premium then
			props.PrefixText = "<font color='#30f56b'>[PREMIUM]</font> " .. message.PrefixText		
		end
	end
	return props
		
end

try like this, also if the problem is in the GetAttribute, you have to check if the player actually has that attribute

Attributes are fine, check out this video

I think I found the issue. The game uses HD Admin, and one of the scripts contains this:

main.textChatService.OnIncomingMessage = function(message)
	if not message.TextSource then
		return
	end
	local player = main.players:GetPlayerByUserId(message.TextSource.UserId)
	if not player then
		return
	end
	
	-- This modifies the chat
	local properties = Instance.new("TextChatMessageProperties")
	local chatTextColor = player:GetAttribute("ChatTextColor")
	if chatTextColor then
		-- For reasons mentioned here it's currently impossible to set chat color
		-- without also setting bubble chat color. Thanks Roblox
		-- https://devforum.roblox.com/t/make-bubble-chat-color-different-from-chat-color/2446865/4?u=foreverhd
		local r,g,b = chatTextColor.R*255, chatTextColor.G*255, chatTextColor.B*255
		--properties.Text = string.format(`<font color='rgb({r}, {g}, {b})'>{message.Text}</font>`)
	end
	print("return message:", properties)
	
	return properties
end

When I deleted HD Admin/before it initialized, it worked, but that executed and broke any other chat scripts.

Brought this issue up to @ForeverHD and he rolled back the change, so this should no longer be an issue for anyone else!

1 Like

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