Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I wanted to make it that whenever I say red on the chat, it prints red. So how do i fix this code?

local Players = game:GetService("Players")
local play1Command = "/red"
local function onPlayerChatted(player, message)
	if message:sub(1, play1Command:len()):lower() == play1Command then
		print("u say red")
	end
end

1 comment

0

Please next time, before you write a question try to find the answer on the web (the official article for Player.Chatted, for example)

1 answer

You forgot to call your onPlayerChatted function

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		onPlayerChatted(plr, msg)
	end)
end)

Put this code somewhere in yours, and it should work

Let me know if I helped

This discussion is preserved as it was. New answers, comments, and votes are closed.