My script can detect if a player said walter or walter7 in any case. I want to expand this to the whole sentence. For example if a player said ("Come Walter") it would still print their name.
for i,currentPlayersChatting in pairs(game:GetService("Players"):GetPlayers()) do currentPlayersChatting.Chatted:Connect(function(msg) if string.lower(msg) == "walter" then print(CurrentPlayersChatting.Name) elseif string.lower(msg) == "walter7" then print(CurrentPlayersChatting.Name) end end) end
How would I expand this to search the whole sentence?
use string.find
to check for a pattern in a string
also, if you're running the same code in the case of multiple different conditions, you should use or
instead of a bunch of if/else statements
so, in your code, that would look like this
for i,currentPlayersChatting in pairs(game:GetService("Players"):GetPlayers()) do currentPlayersChatting.Chatted:Connect(function(msg) local lowerMsg = string.lower(msg) if string.find(lowerMsg, "walter") or string.find(lowerMsg, "walter7") then print(CurrentPlayersChatting.Name) end end) end
also please indent your code properly in the future thaaaaaaaanks