Delete Messages Starting with '-' in сhat

What do you want to achieve?

I would like messages starting with the “-” symbol to be invisible to all players in the chat, allowing me to create commands without broadcasting them to everyone.

What is the problem?

I am unable to achieve the desired result.

What solutions have you tried?

I checked the Developer Center for potential solutions, but I couldn’t find any relevant information.

Thank you for considering my request. I look forward to any assistance!

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg:sub(1, 1) == "-" then
			-- Delete message code
		end
	end)
end)
2 Likes

Don’t use player.Chatted, use the new TextChatService’s ShouldDeliverCallback function:

TextChatService.ShouldDeliverCallback = function(message, textChatSource)
    if message.Text:sub(1, 1) == "-" then
        return false
    end

    return true
end
1 Like

To my knowledge, I’m pretty sure you can’t delete a message in the default-chatbox. You’d have to make your own custom chatbox in order to delete past messages.

1 Like

I got error

ShouldDeliverCallback is not a valid member of TextChatService “TextChatService”

1 Like

Think they made a mistake; it should be called from a TextChannel:

API Reference for ShouldDeliverCallback

2 Likes
local generalChannel: TextChannel = TextChatService:WaitForChild("TextChannels").RBXGeneral
generalChannel.ShouldDeliverCallback = function(message, textChatSource)
    if message.Text:sub(1, 1) == "-" then
        return false
    end

    return true
end
3 Likes

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