I know this title may sound bad, but I had no idea how to phrase it. Anyways, how would I turn this:
"Welcome" to "foo" hello "bar" community "foo bar"
Into this:
{"Welcome", "foo", "bar", "foo bar"}
I've tried looking at the Lua Manual and DevForum but I couldn't find anything.
Rinpix's answer only works if the whole message is in quotes but it doesn't insert the particular quotes into a table.
Here's a proper solution:
game.Players.PlayerAdded:Connect(function(player) player.Chatted:Connect(function(message) local tbl = {} for i in message:gmatch('%b""') do --balanced strings pattern table.insert(tbl, i) end --now you can do whatever with the table "tbl" and the strings in it end) end)
If you want to insert chat messages into a table if they begin and end with quotes, do this in a server script inside of ServerScriptService:
local messages = {} game.Players.PlayerAdded:Connect(function(player) player.Chatted:Connect(function(message) if (#message < 3) then return end if ((message:sub(1, 1) == "\"") and (message:sub(#message, #message) == "\"")) then table.insert(messages, message:sub(2, #message - 1)) end end) end)
Now, I wouldn't just throw a bunch of code at you without actually explaining what's being done.
We set up a table that'll hold all of the messages we want, and assign it to a variable called "messages."
Listen for whenever a player joins, and for whenever they chat. Whenever they chat, make sure the message they're sending is at least 3 characters in length, because there needs to be at least 2 quotes, and a character in between them. If the length of the string is less than 3, exit out of the function. Otherwise, check to see if the first character in the message is a quote, as well as if the last character in the message is a quote. If it is, then insert the message into the table, excluding the quotes.