Custom Chat Message (not working)

I am trying to make it so that when a player types “/keybinds” in the chat a message appears in the chat that has my custom text, and the message only appears for the player that typed “/keybinds”. However, right now the code isn’t printing anything in the chat. Any help would be greatly appreciated! :slight_smile:

local Players = game:GetService("Players")

local function onChat(message, player)
    if message:lower() == "/keybinds" then
        local keybindText = "Here are the keybinds:"
        player:WaitForChild("PlayerGui"):WaitForChild("Chat"):WaitForChild("Frame"):WaitForChild("ChatBar"):WaitForChild("Box"):CaptureFocus()
        game.StarterGui:SetCore("ChatMakeSystemMessage", {
            Text = keybindText,
            Color = Color3.fromRGB(255, 255, 255),
        })
    end
end

Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(message)
        onChat(message, player)
    end)
end)
1 Like

It’s because of the /, so what you can do is string.sub()

local Players = game:GetService("Players")

local prefix = "/"

local function onChat(message, player)
    if string.sub(message, 1, 1) == prefix then
       if string.sub(message:lower(), 2, #message) == "keybinds" then
         -- code
       end
    end
end
1 Like

Try this:
Localcode:

-- Place this script in StarterPlayer and StarterPlayerScripts

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

local chatEvent = ReplicatedStorage:WaitForChild("ChatEvent")

local function displayChatMessage(message)
	print("Received chat message:", message)

end

chatEvent.OnClientEvent:Connect(displayChatMessage)

Servercode:

-- Place this script in ServerScriptService or ServerStorage thanks

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

local chatEvent = Instance.new("RemoteEvent")
chatEvent.Name = "ChatEvent"
chatEvent.Parent = ReplicatedStorage

local function onChatCommand(player, message)
	if message:lower() == "/keybinds" then
		
		--set here your kebinds man
		local keybindText = "Here are the keybinds: Jump - Space, Move - WASD, etc."
		
		chatEvent:FireClient(player, keybindText)
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		onChatCommand(player, message)
	end)
end)

And the game.StarterGui:SetCore("ChatMakeSystemMessage, { dosent work on new roblox chat u need to change it to Legacy
ChatService > ChatVersion > LegacyChatService

1 Like

It prints the text in the Output but not in the game chat for the player to read in-game

1 Like

ik, game.StarterGui:SetCore("ChatMakeSystemMessage, { dosent work on new roblox chat u need to change it to Legacy
ChatService > ChatVersion > LegacyChatService

i did change it to the legacy chat like you mentioned but it’s still not working

1 Like