How to get a character out of a string with index

hello, i want to get a character out of a string but it keeps returning nil

str = "hello"
print(str[1])
1 Like

Because string doesn’t have the index number 1 therefore it returns nil.

You’re looking for string.sub(s, i, j) as that gets the substring of a string from i to j. string.sub(str, 1, 1)

7 Likes