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

Tables with Chatted event help?

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

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)

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