for i,v in pairs(values) do if string.lower(v):sub(1, #text) == string.lower(text) then first.Text = v second.Text = v third.Text = v fourth.Text = v end end
So I'm trying to make a suggestion box where there are 4 different suggestions that auto complete words from a table as a player is typing something (which is text). It works all fine, but I can't figure out how to get second.Text get a different value from the pairs loop, and then third.Text to have another value etc. Any help please?
You need an if statement as shown below
local myTable = {"Hello", "Bye", "Good Day", "Hi", "Hey", "Buh-Bye", "Good afternoon", "Good evening"} game.Players.PlayerAdded:Connect(function(Player) Player.Chatted:Connect(function(text) local first,second,third,fourth = nil for _,word in pairs(myTable) do if string.lower(word):sub(1, #text) == string.lower(text) then --This is what you needed. --Checks to make sure the words are not empty if not first then first = word elseif not second then second = word elseif not third then third = word elseif not fourth then fourth = word end end end print(tostring(first)) print(tostring(second)) print(tostring(third)) print(tostring(fourth)) end) end)