Prevent players' messages showing up in chat

I am trying to make it so when a player sends a message via the roblox chat the message only appears to close players, however I can’t figure out a way to do it (make it so it doesn’t appear in chat), I’ve looked all around the forum but couldn’t manage to find solutions, at least with the new chat service, it would be of great help how to make it so the message doesn’t appear in chat for everyone, then I can figure out everything else on my own. I have been trying to do this for hours but to no avail. Any help is greatly appreciated.

turn off the Enabled property of ChatWindowConfiguration under TextChatService

1 Like

You can use TextChannel.ShouldDeliverCallback in a server script:

local chat = game:GetService("TextChatService")
local channel = chat:FindFirstChild("RBXGeneral", true) -- change this if you are using a different channel

local maxDistance = 100 -- in studs

channel.ShouldDeliverCallback = function(message, source)
    local sender = game.Players:GetPlayerFromUserId(message.TextSource.UserId)
    local receiver = game.Players:GetPlayerFromUserId(source.UserId)

    if (sender.Character.HumanoidRootPart.Position - receiver.Character.HumanoidRootPart.Position).Magnitude <= maxDistance then
        return true
    end

    return false
end

(this is untested, but it should work)

it says ShouldDeliverCallback is not a valid member of TextChatService

My bad, edited the code now to fix it

I don’t want it to be completely disabled, I just want the player to send the message, which won’t show up in the text box, then I will send a message from the server that will look like the player’s to only the people close by, thus making it appear in the text box only if you’re nearby

still doesn’t appear to work, I tried replacing the magnitude checker with a filter that returns true only if the message is “HI” but whenever I send a message it doesn’t even fire the event, it doesn’t matter if I put it on a server side script or a client one for what it seems

Alright, I actually tested my code now like a normal person, here is the fixed version:

local chat = game:GetService("TextChatService")
local channel = chat:WaitForChild("TextChannels"):WaitForChild("RBXGeneral") -- change this if you are using a different channel

local maxDistance = 100 -- in studs

channel.ShouldDeliverCallback = function(message, source)
	local sender = game.Players:GetPlayerByUserId(message.TextSource.UserId)
	local receiver = game.Players:GetPlayerByUserId(source.UserId)

	if (sender.Character.HumanoidRootPart.Position - receiver.Character.HumanoidRootPart.Position).Magnitude <= maxDistance then
		return true
	end

	return false
end
2 Likes

I’m not crazy familiar with the new chat service, but I believe you get the default TextChannel, then set the TextChannel.ShouldDeliverCallback to a function like:

local function shouldDeliverCallback(message, textSource)
    local senderUserId = message.TextSource.UserId
    local sendingToUserId = textSource.UserId
    -- TODO: Get the characters for the user IDs
    --       Return if the difference in position is small enough (aka true/false)
end

Edit: See BackspaceRGB’s solution for more information on this

The script is firing when I send a message, however how do I know what’s the text in the message? “message” seems to return the player

You do message.Text

message is a TextChatMessage (documentation), so it should be just message.Text

1 Like

Yeah that part works however the message still pops up in the chat box, it’s server-side right?

no, any involvement with TextChatService is always client-side

Thank you it’s working, I just didn’t test it in a server and didn’t consider it would be visible to who did it, but now I figured it out.

1 Like

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