Chatted Event Help

How Can I make My Chatted Event Run If the Player doesn’t Write the message Exactly As Shown in the script?

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg == "Bob Is Cool" or msg == "Bob Is Epic" or msg == "Bob Is My Friend" then -- Fixed this line to check msg against both strings
			wait(2)
			game:GetService("Chat"):Chat(game.Workspace.Bob.Head, "Thanks :)")
		end
	end)
end)

Thanks :slight_smile:

I am a bit confused on what your asking here. How can you make a chatted event runs if a player does not write the message?

The Player.Chatted event is run when someone sends a message into the chat so it should work as it is?

It won’t work if they say, For Example, “bob is epic” (Lowercase)
It will work if they Say “Bob Is Epic” (How it’s written in the code.)

Ah ok, so the issue that you have is that due to you comparing the message exactly for the string in the if statement it does not check to see if the message is capitalized or not.

To fix this issue, what you could do is make it so the strings in the if statement are not capitalized and then use the method :lower() on the string you get when the user sends a message.

1 Like

Can You Make an Example Please?

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		local MsgLower = msg:lower()
		if MsgLower == "bob is cool" or MsgLower == "bob is epic" or MsgLower == "bob is my friend" then -- Fixed this line to check msg against both strings
			wait(2)
			game:GetService("Chat"):Chat(game.Workspace.Bob.Head, "Thanks :)")
		end
	end)
end)

Or what I personally recommend to make your code a bit neater and lets you easily add more messages in the future:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.