How would I remove a chat with the new TextChatService?

In murder mystery, there is a system to where you can’t see players chats who are in the lobby, how do I do this with TextChatService?

3 Likes

I am going to assume you are using “Lobby” as a waiting room for the next round.

One possible solution is to create a custom TextChannel and utilize the “.ShouldDeliverCallback” callback. You could then add an attribute to all members upon the start of a round, where it would be used to indicate if they are participating in the round or not. You should then use the “.ShouldDeliverCallback” callback to check if the member has the attribute of participating in the round or not. If both the message sender(s) and receiver(s) don’t have the same attribute, then the message wont be seen by both.

Another solution could be to just add/remove players from multiple custom TextChannels, based on the same concept of whether they are actively participating in the current round or not. However, I believe the previous solution is more optimal.

You can find out more about TextChannels and the “.ShouldDeliverCallback” callback here:

6 Likes

But does this remove it for one player or for all other players?

3 Likes

It does it for every player. So if I am not participating and other members are participating, all members who are participating won’t receive my message.

3 Likes

But what if another player isn’t participating will they see the message?

3 Likes

Yes.

It is dependent on return of true or false in your “ShouldDeliverCallback” function too. So if you wanted to, you can make it so the lobby can see the game chat, but the game can’t see the lobby chat.

3 Likes

Tyler can you explain how I would do this, because the way you explained it was very confusing. I don’t use call back very often so I don’t really know how they work when it comes to roblox, especially with TextChatService.

2 Likes

Ok I will try my best to explain.

Create a TextChannel in the TextChatService in Roblox Studio by clicking the “+” next to the TextChatService section. You can name this TextChannel whatever you would like, for my example I named it “Default”.

Next you must create a server-script which references that TextChannel and adds all users upon joining the experience. This can be done by doing something like this:

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

local DefaultChannel = TextChatService:WaitForChild("Default")

Players.PlayerAdded:Connect(function(plr)
	DefaultChannel:AddUserAsync(plr.UserId)
end)

Then in that same script you can create a callback function, which returns a true or false value. For the example I was stating above, it would look something like this.

function getPlayerByUserId(userId)
	return Players:GetPlayerByUserId(userId)
end 

DefaultChannel.ShouldDeliverCallback = function(textChatMessage, targetTextSource)
	local sender = getPlayerByUserId(textChatMessage.TextSource.UserId)
	local target = getPlayerByUserId(targetTextSource.UserId)
	
	return (sender:GetAttribute("Participating") == target:GetAttribute("Participating"))
end

Messages are linked to the userId of the sender, so it grabs the player from the userId provided. It then checks to see if both Players have the attribute equaling the same value, meaning both true or both false. As previously stated, you could always modify this callback to make it so game chat is shown to the lobby members.

So now with this script, whenever a round starts, grab all players who are participating in the round and add/set an attribute to them. This can be done using :SetAttribute("Participating", true).
When a player is no longer participating in the round, lets say they die, you do :SetAttribute("Participating", false).

One final thing you must do is create a LocalScript and insert it into “StarterPlayerScripts”. This script is used to change the player’s TargetTextChannel in order to type in the TextChannel you created.
This can be done like so:

local TextChatService = game:GetService("TextChatService")

TextChatService.ChatInputBarConfiguration.TargetTextChannel = TextChatService:WaitForChild("Default")
4 Likes

I didn’t use it, because I decided to make my own chat system, but this would probably work anyways, so I marked as solution.

1 Like

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