Hi!, simple question.
When using TextChatService, how can we ensure that the player who sent a chat message is unable to see their own message in the chat panel?
I don’t think it’s documented anywhere but you can set the TextChatMessageProperties.Text to a whitespace character (ie a space), this should allow others to see the message but not the local player. This prevents the message from showing up entirely
local players = game:GetService('Players')
local textChatService = game:GetService('TextChatService')
local localPlayer = players.LocalPlayer
function textChatService.OnIncomingMessage(message)
local source = message.TextSource
if not source or source.UserId ~= localPlayer.UserId then
return
end
local params = Instance.new('TextChatMessageProperties')
params.Text = ' '
return params
end
Its exactly what Im trying, but the OnIncomingMessage()
callback cant be set like that, I did this, and seems like working:
TCS.OnIncomingMessage = function(textChatMessage: TextChatMessage)
textChatMessage.Text = ""
end
Im not sure yet, Im testing it, but seems like working fine
I don’t think you can write to the TextChatMessage itself. Update: apparently you can but I don’t know whether or not it’s intentional
The callback can be assigned either way as it’s just syntax sugar, but the TextChatProperties.Text needs to have a whitespace character (" "
), a blank string like that won’t work because it’s the default property for the TextChatProperties, there would be an ambiguity between having no option set and having the text be a blank message
Im still checking, yeah… what I did seems like working, its just idk.
About how to set the callback I get this error if I do it like this, what what I meant:
TCS.OnIncomingMessage:Connect(function(msg)
Oh my bad I didn’t realize it worked. That being said, if I were you I’d opt for the TextChatMessageProperties method since that’s the officially documented mean of modifying chat messages, I wouldn’t rely on being able to write to the actual TextChatMessage.
In fact looking at the docs it says that TextChatMessage is supposed to be immutable (not modifyable): TextChatMessage | Documentation - Roblox Creator Hub
Oh yeah a callback is different than connecting to a signal. A signal is basically a property of the relevant object, it’s another object that can be subscribed to, the function will run whenever said signal is fired. It can be subscribed to an indefinite number of times of course.
A callback can only be assigned once at a time, it’s more or less the same as writing a function in a module, or something of that nature. But instead of writing to a table you’re writing to an instance
I agree with that, perhaps being able to write on the TextChatMessage is not an intended feature. I think you are right and I will try with the Properties instead, thank you!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.