Print help message in chat

I’m trying to figure out how to print a help message in chat similar to what you get when you type /help and it gives you a list of commands like in the following image:
image
Right now, I’m using a print message from a speaker that I created to send the message, but the message is shown to all players. I need it to show only to the player that requested it.

1 Like

Well, add a LocalScript in StarterPlayerScripts or StarterGui. Make a function with the following content;

--Get the StarterGui service
local StarterGui = game:GetService("StarterGui")

--Use a repeat to make sure we get our system message
--The repeat will only stop once the function successfully runs
repeat
	wait() --Wait to prevent crashing
	local Success = pcall(function()
		--Run SetCore method inside the pcall
		--The first argument of SetCore is the method we wish to use
		--In this case, the second argument is a dictionary of data for the chat message
		StarterGui:SetCore("ChatMakeSystemMessage", {
			Text = "This is a system message"; --The chat message
			Color = Color3.fromRGB(0, 255, 255); --Chat message color, defaults to white
			Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
			TextSize = 18 --Text size, defaults to 18
		})
	end)
until Success

(Refer to Make script post message in default chat? - #4 by Extuls for the full code and explanation).

Then connect this function to the Player.Chatted event.

Ok, I did get this working, with one problem. All the texts go into the All channel which I am not using in my game. I need it to display to the player that made the request, on the channel they made the request on.

There is a way by setting a new speaker for the channel. However, I never did this (or studied it), so I can only provide you with the link to an already existing thread:

(Method 2)

I’m already using method 2 on the server, which is the problem. It broadcasts to everyone on the channel. So if someone types /help on the channel, everyone sees it. I need it to display ONLY to the player that typed the request, and ONLY on the channel the request was typed on. This means that I’m going to have to trace the Roblox code to figure it out. The link you gave was provided by you in post #2. I read that post, which is how I got method 1 working.

I am unsure if you can use method 1 on a certain channel. I doubt.

Method 1 does not have a way to specify the channel, so it prints to the All channel which I’m not using. However, I’m looking through all the chat code (it’s significant) and I figured it out. When the game is running, there is a module script called ChatCommandsTeller located at Chat -> ChatModules. That’s where the chat help message is being printed from. Based on Roblox code, I got it working.

local function Run(chatService)
	
	-- Tokenizes a string into a table and returns it
	-- if the command prefix is valid, or nil if not.
	local function tokenizeString(str)
		local tokens = string.split(str, " ")
		local prefix = string.sub(tokens[1], 1, 1)
		tokens[1] = string.sub(tokens[1], 2)
		if prefix == "/" then
			return tokens
		end
		return nil
	end
	
	-- Command Execution
	local function showCommands(speakerName, message, channelName)
		
		-- Setup
		local tokens = tokenizeString(message)
		if tokens == nil then
			return false
		end
		local speaker = chatService:GetSpeaker(speakerName)
		local command = string.lower(tokens[1])
		
		if command == "commands" then
			local textstr
			if tokens[2] == nil then
				textstr = string.format("List of valid commands:\n")
				-- Add help text here
				textstr ..= string.format("\nType: commands <command> for more information about that command.")
			else
				local helpcmd = string.lower(tokens[2])
				textstr = string.format("Help for command %s.\n\n")
				-- Add help text here
			end
			speaker:SendSystemMessage(textstr, channelName)
			return true
		end
		return false
	end
	
	-- Register Callback Function	
	chatService:RegisterProcessCommandsFunction("showCommands", showCommands)
end

The key point is speaker:SendSystemMessage() which only the speaker can see.