There are a few problems with your code that I will attempt to address while also answering your question. The problem you have is relatively common. How do we check to see if one of many options works? There is are a few methods that I can think of. However, the one that I recommend for large amounts of options is thus: Use a table that contains all of the options.
local phrases = {"hello", "hey", "hi"}
Now if we were to check the table using an if statement it would not work. Here is an example:
if msg == phrases then
Why would this not work? The reason is that when you check if msg = phrases you are merely checking if the msg = table not if msg matches any of the actual items in the table. So how can we check against each item in the table? We can use a for loop similar to the one you used. Now we could do:
for i = 1, #phrases do
if msg == phrases[i] then
end
end
But Lua has a useful way to loop through tables that is even easier than that. Here is how I would use it:
for i,v in pairs(phrases) do
if msg == v then
end
end
Now here is where I want to address some problems in your code. GetService() is the recommended method for getting services like the "Players" service. Here is how you use it:
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
for i,v in pairs(phrases) do
if msg == v then
end
end
end)
end)
The reason I got rid of the loop you had on line 12 is because that would affect all the players. Every player on the server would have gotten a badge if one player did the action necessary to get the badge. Also you should make sure the player does not already have the badge before awarding it to them. :connect() is deprecated you should use :Connect() instead. The variable source seems unnecessary to me but you might have another use for it that I do not know. I hope that this answer helps and that you will have a great day scripting!
Edit:
If you wanted them to have to say all of the words at once then you would have to do something like this:
players.PlayerAdded:Connect(function(plr)
local amountOfWordsSaid = 0
plr.Chatted:Connect(function(msg)
for i,v in pairs(phrases) do
if string.match(msg, v) then then
amountOfWordsSaid = amountOfWordsSaid +1
if amountOfWordsSaid == #phrases then
end
end
end)
end)
Hope this better fits your question!
4 comments
you shouldn't use PlayerAdded and GetPlayers
you should *
I edited my answer to better help you out.
Sorry I forgot that I should set it to zero first because I am adding to it.