Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Tables with Chatted event help?

Asked by 8 years ago

So basically I need to know how I would do this using a table for more than one word:

game.Players.PlayerAdded:connect(function(plr) plr.Chatted:connect(function(msg) if msg == 
        "start" then if plr.Name == captain1 then
        start()
    end)
end)

How would I add a table in which could be used in place of "if msg == "start""

the table would look like this:

local words = {"start","begin","play"}

Would I simply replace "if msg == "start"" with "if msg == words then" Or would it be something like "if msg[words] then"

*Excuse my few errors if there are.

1 answer

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

You can simply iterate through each value in the table using a generic for loop.

local words = {"start", "begin", "play"}

game.Players.PlayerAdded:connect(function(plr)
    plr.Chatted:connect(function(msg)
        for _, word in next, words do
            if msg == word then
                if plr.Name == captain1 then --Assuming captain 1 is declared
                    start()
                end
            end     
        end
    end)
end)
Ad

Answer this question