TextChatCommand Question

I want to use TextChatService (TextChatCommand), and when I type a special command like “/Tryout,” I don’t want the message bubble to show up. But if I just talk regularly with someone, the bubble should show up like normal. It’s like a secret message bubble that only hides when I use a special command.

I’ve been trying to find a solution with 25 tabs open, but I can’t figure it out. Can someone help me with this?

I already have some code for detecting if i typ ‘/Tryout’ in the chat.

Someone, i don’t even know if this is supported tbf

Could you show your original code for the command? It’s way easier to work with existing code rather than making my own.

-- // Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextChatService = game:GetService("TextChatService")

-- // Variables
local Announcement = ReplicatedStorage:WaitForChild("Remotes").Announcement
local lockRemote = ReplicatedStorage:WaitForChild("Remotes").Border.lock
local unlockRemote = ReplicatedStorage:WaitForChild("Remotes").Border.unlock


local CommandPrefix = "/"

-- // Functions
function CreateTextChatCommand(CommandName: string, Callback: (TextSource: TextSource, String: string, self: {any}) -> (any), PrimaryAlias: string, SecondaryAlias: string?): TextChatCommand
	local self = {}
	assert(typeof(CommandName) == 'string', "Expected string, got '"..typeof(CommandName).."' for CommandName.")
	assert(typeof(PrimaryAlias) == 'string', "Expected string, got '"..typeof(PrimaryAlias).."' for PrimaryAlias.")	

	self.CommandName = CommandName
	self.Callback = Callback
	self.PrimaryAlias = CommandPrefix..PrimaryAlias

	if SecondaryAlias then
		self.SecondaryAlias = CommandPrefix..SecondaryAlias
	end

	self.TextChatCommand = Instance.new("TextChatCommand", TextChatService)
	self.TextChatCommand.Name = self.CommandName
	self.TextChatCommand.PrimaryAlias = self.PrimaryAlias

	if self.SecondaryAlias then
		self.TextChatCommand.SecondaryAlias = self.SecondaryAlias
	end

	self.TextChatCommand.Triggered:Connect(function (TextSource, String)
		local s, e = pcall(function ()
			Callback(TextSource, String, self)
		end)

		if e then
			warn("Error with callback: "..e)
		end
	end)
	return self
end

function MyFunction(TextSource, MessageString, self)
	local args = string.split(MessageString, ' ')
	Announcement:FireServer(args)
end

function lock(TextSource, messageString, self)
	local args = string.split(messageString, " ")
	lockRemote:FireServer(args)
end

function unlock(TextSource, messageString, self)
	local args = string.split(messageString, " ")
	unlockRemote:FireServer(args)
end

CreateTextChatCommand("AnnouncementCommand", MyFunction, "Tryout")
CreateTextChatCommand("BorderPadsCommand", lock, "Lock")
CreateTextChatCommand("BorderPadsCommand", unlock, "Unlock")

This is supported for sure, I have seen many games do it.

You can disable the automatic chat bubbles with a property (I forget which service) and then have a script send a chat bubble manually when the player chats as long as their message isn’t in a table of commands.
Alternatively, I think you could disable the ui that is put into players’ characters when they chat if a command was detected. (This might not work)
You also might be able to clear the string being sent to chat before it arrives, but I’m not sure how to do that.

I would provide code but I’m on mobile. Hope this helps!

I have no clue how that would work with TextChatCommands, Cuz it makes the textChatCommands automatically. And detecting every single message a player would sent would be a bit overkill. Since there will be around 100/200 players in a server.

Isn’t there an easier way of doing this?

This would probably help you : Solution for chat send system

I found a quick but stupid solution.

function MyFunction(TextSource, MessageString, self)
	local args = string.split(MessageString, ' ')
	Announcement:FireServer(args)
	BubbleChatConfiguration.BubbleDuration = 0
	task.wait(.1)
	BubbleChatConfiguration.BubbleDuration = 15
end

Which isnt really reliable sadly

You can use a TextChatCommand. They do exactly what you expect.

First create the TextChatCommand as a descendant/child of TextChatService. You can do this in Studio Edit or via a server-side script. Set the PrimaryAlias property to ‘Tryout’

then in a server or local script, use this to detect the command being used:

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

TextChatService.theTextChatCommandYouMade:Connect(function(source, text)
    local player = Players:GetPlayerByUserId(source.UserId)
    print(`{player.Name} said the command {text}!`)
end)

Don’t forget to change theTextChatCommandYouMade to the path to the command you created. I’m unable to test if the code example provided actually works right now, but hopefully it guides you in the right direction!

You know i already do that. I just want to hide the bubblechat above the players head only when a command is fired. When the player is talking normally i want it to be visible

self.TextChatCommand.Triggered:Connect(function (TextSource, String)
		local s, e = pcall(function ()
			Callback(TextSource, String, self)
		end)

		if e then
			warn("Error with callback: "..e)
		end
	end)

I think its sadly not possible at this very moment

Bump )charzzzzzzzzzzzzzzzzzzzzz

I don’t think it will display the bubble chat; Here I am using my own admin system, using text chat commands

here is the triggered code if that matters:

TextChatCommand.Triggered:Connect(function(textSource, rawText)
			if not textSource then
				return
			end
			
			local Caller = Players:GetPlayerByUserId(textSource.UserId)
			local TextChannel = textSource.Parent :: TextChannel
			
			if not Utilities.IsPlayerAuthorized(Caller, CommandMetaData.Authority) then
				return
			end
			
			local RawArguments, ParsedArguments = ParseMessage(Caller, rawText, CommandParsers)
			local Context = {
				Caller = Caller;
				RawMessage = rawText;
				RawArguments = RawArguments;
				Arguments = ParsedArguments
			}
			
			local CommandSession = {
				TextChannel = TextChannel;
				CommandObject = CommandObject;
				Context = Context;
			}
			
			CommandSessionData[Caller] = CommandSession
			
			if CommandMetaData.ConfirmBeforeExecuting then
				ConfirmationRemote:FireClient(Caller, Context.RawMessage)
			else
				ExecuteCommand(CommandSession)
			end
		end)