Help with using values from a table with :split()

Hi!
Currently, my code generates a table of the words in the text box using :split(" ")
I need a way to access the specific words in the table
table:

table: 0x35a30bb16995dfe5 = {
   [1] = "test1",
   [2] = "test2"
 }

code:

local split = commandString.Value:split(" ")
print(split)

You can simply access the words in the table by expanding on your existing code and referencing the number position of each word in the table:

local split = commandString.Value:split(" ")
local word1 = split[1] -- gets the word in number position 1

Obviously, you don’t need to use another variable, and you could just say:

local word1 = commandString.Value:split(" ")[1] -- gets the word in number position 1

The number can be changed to access different words in the table. For example, if I wanted the second word, I would say split[2], etc.

3 Likes