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

Detect when player says a letter (but)?

How do I detect when a player says a letter no matter if its capital or not? I have a randomizing script that puts a StringValue with a Value of a Random Letter inside a player. (its like "C" or "K") I need a script that detects when a player says this letter in any word or sentence [No matter if the letter is capital or not!]

1 answer

✓ Accepted answer

Use Player.Chatted event. Use string.find() to detect if a string contains a specific letter/word.

game.Players.PlayerAdded:Connect(function(player) -- when a player joins
   player.Chatted:Connect(function(message, recipient) -- when a player chats
      if string.find(message:lower(), "foo") then -- checks if the message contains the word "foo"
         print("The message contains the word foo!") -- prints if the message actually contains the word "foo"
      end
   end)
end)

2 comments

0

It doesnt work, when i type a letter it doesnt print out anything

0

instead of "text" i use a value so its just --> letter not "letter"

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