I'm trying to make a script so when i type "-get" followed by a string in the table (for example "-get blue") it would print "worked" like it is supposed to, how would i make it check if the argument matches a string in the table?
list = {"yellow", "blue"} game.Players.PlayerAdded:Connect(function(plr) plr.Chatted:Connect(function(msg) local msg = msg:lower() if string.sub(msg,1,5) == "-get" and string.sub(msg,6) == list then print('worked') else print('didnt work') end end) end)
You can use string.find (https://developer.roblox.com/en-us/api-reference/lua-docs/string) and plug in the wanted keyword and the given string.
Furthermore, use a for-each loop to go through every element of the list.
For example:
for i = 1, #list do if string.find(msg, list[i]) ~= nil then print("found " .. list[i]) end end
You can use table.find or a for loop. I used table.find
because it's simply finding a value that matches the one we have. Example:
local string_1='Wow potato'; local fav_foods={'potato';'pizza';}; string_1=string_1:sub(5); if table.find(fav_foods,string_1)then print'yum'-->yum end;
You can use the other answer but there is still one problem you said string.sub(msg, 1, 5) == "-get"
you forgot to put a space after -get