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
This is not really an answer with a lot of effort but I'm just going give a link to the roblox developer website. Maybe it will help a little. idk.
This function returns the [TextBox] the client is currently focused on. A TextBox can be manually selected by the user, or selection can be forced using the [TextBox:CaptureFocus](https://developer.roblox.com/api-reference/function/TextBox/CaptureFocus)
function.
If no TextBox is selected, this function will return nil.
As [UserInputService](https://developer.roblox.com/api-reference/class/UserInputService)
is client-side only, this function can only be used in a [LocalScript](https://developer.roblox.com/api-reference/class/LocalScript)
.