System Chat Commands

Hey Developers!

I am trying to make a system when a user says “/question how do i play this game” then a system message says “To play this game you walk over to the teleport pad!”

I have already tried several things but they have all failed.

If anyone could help me with this it would be great!

Thanks!

3 Likes

You’ll need to get the Roblox ChatService module in order to do this, then:

local function SendMessage(Player, String)
	local Speaker = ChatService:GetSpeaker(Player.Name)
	if Speaker then
		Speaker:SendSystemMessage(String, Channel) -- Channel should be 'All'. As that's the public channel.
	end
end

For the question part, you’ll need a Chatted event:

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		if Message:lower() == '/question how do i play this game' then
			SendMessage(Player, String)
		end	
	end)
end)

This is just an example.

1 Like

Okay Great! I still cant get it to reply as a message though, I have tried a few things like

if Message:lower() == '/question how do i play this game' then
			local msgcol = BrickColor.new("White")
			game.StarterGui:SetCore("ChatMakeSystemMessage", { 
				Text = "{System} Welcome to the server! Enjoy!"; 
				Font = Enum.Font.Cartoon; 
				Color = msgcol.Color; 
				FontSize = Enum.FontSize.Size96;	
			})

Is that your full script?
If not, please include the rest.

This is it

local function SendMessage(Player, String, Channel, mscgcol)
	local ChatService = ("ChatService")
	local Speaker = ChatService:GetSpeaker(Player.Name)
	if Speaker then
		Speaker:SendSystemMessage(String, Channel) -- Channel should be 'All'. As that's the public channel.
	end
end 

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		if Message:lower() == '/question how do i play this game' then
			local msgcol = BrickColor.new("White")
			game.StarterGui:SetCore("ChatMakeSystemMessage", { 
				Text = "{System} To play the game. Walk over to the teleport pad!"; 
				Font = Enum.Font.Cartoon; 
				Color = msgcol.Color; 
				FontSize = Enum.FontSize.Size96;	
			}) --
		end	
	end)
end)

StarterGui:SetCore must be called from a local script.
If you wish to use it, you’ll need to have a RemoteEvent and use FireClient(), then go from there.

(Or simply set up a Chatted event in a localscript).

I tried it in a local script but it still didn’t work.