Hello! I’m trying to make a lobby chat system. How it works is a lobby is created and the lobby is named L_creatorname. Each client has an OnIncomingMessage callback that checks if the channel’s name starts with an “L_”. If so, the message is supposed to turn into a light green color and gets the prefix [Lobby] to it.
Players can send messages through a surface gui in workspace but I am certain that the message sends because it prints the PrefixText to the output without any issues.
Here is the callback
TextChatService.OnIncomingMessage = function(Message: TextChatMessage)
local Properties = Instance.new("TextChatMessageProperties")
local Source = Message.TextSource
local Channel = Message.TextChannel
if Source and Message.Status == Enum.TextChatMessageStatus.Success then
if string.match(Channel.Name, "L_") then
Properties.PrefixText = string.format("<font color='#90EE90'>[Lobby] %s</font>", Message.PrefixText)
Properties.Text = string.format("<font color='#90EE90'>%s</font>", Message.Text)
print(Properties.PrefixText)
local MonitorText = ReplicatedStorage.Storage.LobbyChatMessage:Clone()
MonitorText.Text = `{Source.Name}: {Message.Text}`
MonitorText.Parent = ChatMonitorFrame.ScrollingFrame
end
end
return Properties
end
But what actually happens is the messages sends and the text changes color perfectly fine, however this cannot be said for the PrefixText. it only changes randomly, depending on whoever knows.
It doesn’t only happen the first time, it happens very randomly. It’s also pretty rare to see it since it took me like a few tries to get the text.
Could you send the file perchance? I’ve used OnIncomingMessage and never had this issue. Taking a deeper look would be nice. So the output displays the correct PrefixText for each message? And what is the MonitorText?
Hey, thanks for the reply!
After re-reading the topic, I realized I explained it pretty terribly.
You shouldn’t really worry about monitor text - it’s just a surface gui inside workspace that displays messages inside the channel, I removed it to test and the result is the same.
I also used OnIncomingMessage before and it worked perfectly fine, I don’t know why its doing this all of a sudden.
Unfortunately I can’t send the game file since it’s not a test. The script inside the topic is the whole script.
This is the script that creates the channel and appends the players, a server script
local function CreateLobby(Players)
local NewTextChannel = Instance.new("TextChannel"); NewTextChannel.Parent = game:GetService("TextChatService"):WaitForChild("TextChannels")
NewTextChannel.Name = `L_{Players[1].Name}` -- the lobby is named after the creator, aka the #1 index of the table
for _, Player in pairs(Players) do
NewTextChannel:AddUserAsync(Player.UserId)
end
return NewTextChannel
end
Its most likely because of this line right here. A message Status (Enum.TextChatMessageStatus) can only be one, and there is Success, and Sending. And likely it hasn’t been able to send the message as this is all happening before the message is sent (when you set prefix and various other things with OnIncomingMessage Event, the Message hasn’t sent it, as the event name Suggests, On Incoming Message) , which is what Enum.TextChatMessageStatus.Success is. Try the following code and lmk if it works! (All I did was made a table with 2 different MessageStatus Enum’s and if the Message is one of those 2 Enums, it will apply the Prefix)
local AllowedStatus = {Enum.TextChatMessageStatus.Success, Enum.TextChatMessageStatus.Sending}
TextChatService.OnIncomingMessage = function(Message: TextChatMessage)
local Properties = Instance.new("TextChatMessageProperties")
local Source = Message.TextSource
local Channel = Message.TextChannel
if Source and table.find(AllowedStatus, Message.Status) then
if string.match(Channel.Name, "L_") then
Properties.PrefixText = string.format("<font color='#90EE90'>[Lobby] %s</font>", Message.PrefixText)
Properties.Text = string.format("<font color='#90EE90'>%s</font>", Message.Text)
print(Properties.PrefixText)
local MonitorText = ReplicatedStorage.Storage.LobbyChatMessage:Clone()
MonitorText.Text = `{Source.Name}: {Message.Text}`
MonitorText.Parent = ChatMonitorFrame.ScrollingFrame
end
end
return Properties
end
If it were me I would even remove the If statement and just leave if Source then however I can see what your trying to do, which is why I kept it the same.