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:
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
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
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.