Hello i am currently working on a game and i had ran into a problem. I am generating a couple TextBoxes on another script and i wanted to do so that when you press "Return" key on the keyboard it would get you to the next textbox. All of my text boxes are generated with the name of "TextBox" and a number which goes from 0 to 209. My problem is that i am getting an error on this line:
local TextBoxFocused = UserInputService:GetFocusedTextBox()
The error says the following: attempt to index local 'TextBoxFocused' (a nil value)
If i understand correctly, it says that TextBoxFocused is nil. I tried with a text box called "TextBox" and it worked just fine but a text box with the number at the end gives me the error. Any clues why?
Script:
wait(0.02)
for i,v in pairs(script.Parent:GetChildren()) do
if string.match(v.Name, "TextBox") then
print(v.Name)
v.Text = ""
v.ClearTextOnFocus = false
end
end
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:connect(function(input)
if UserInputService:GetFocusedTextBox() ~= nil then
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
end
end)
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.Return then
local TextBoxFocused = UserInputService:GetFocusedTextBox()
local CharacterAfterO = string.find(TextBoxFocused.Name, "o")
print(string.sub(TextBoxFocused.Name, CharacterAfterO + 2))
print("HI")
end
end
Please Help, Thank you
Nachsor

4 comments
No
Yah, I wouldn't think that's a thing
And even if there was no textbox, and it was nil that shoul'nt error, it will just be set to nil. Are you sure the error is from that line?
Yes, I am fairly certain. This is the full error just incase it helps: 11:40:23.248 - Players.nachsor.PlayerGui.ScreenGui.ScrollingFrame.ChangeText:26: attempt to index local 'TextBoxFocused' (a nil value). When I click on the error, it gets me straight to line 26. This one, local CharacterAfterO = string.find(TextBoxFocused.Name, "o")