It is saying I have an invalid argument. Help please! Code
local spaceLocations = {}
local keyTerms = {}
script.Parent.MouseButton1Click:Connect(function()
for i=1, string.len(script.Parent.Parent.InputBox.Text) do
if string.sub(script.Parent.Parent.InputBox.Text, i, i) == " " then
table.insert(spaceLocations, i)
end
end
for i,v in ipairs(spaceLocations) do
print(v)
end
for i=1,#spaceLocations+2 do
if i == 1 then
table.insert(keyTerms, string.sub(script.Parent.Parent.InputBox.Text, 1, spaceLocations[1]))
elseif i == #spaceLocations+2 then
table.insert(keyTerms, string.sub(script.Parent.Parent.InputBox.Text, spaceLocations[i], string.len(script.Parent.Parent.InputBox.Text)))
else
local term = string.sub(script.Parent.Parent.InputBox.Text, spaceLocations[i], spaceLocations[i]) --Line 56
table.insert(keyTerms, term)
end
end
for i,v in ipairs(keyTerms) do
print(v)
end
end)
Error
21:53:55.851 - Players.benben3963.PlayerGui.ScreenGui.Frame.SearchButton.LocalScript:56: bad argument #2 to 'sub' (number expected, got nil)

5 comments
You added +2 numbers to the loop, how come? (Line 13)
No reason, I addressed those two added numbers with the if statements. I just want to know why line 19 is not working.
Try to print spaceLocations[i] if it is a number
error is saying that spaceLocations[i] is nil
Mhm, b/c of those 2 added numbers, it's trying to get positions that have no value. :P To stop this, simply do
if spaceLocations[i] then