I’m trying to make a terminal-like GUI that players can enter commands into. I have a table that will store the 10 most recent commands the user has entered, and then give them the ability to automatically get those commands back by hitting the up or down arrow keys while they are focused on the TextBox use to enter commands. However, for whatever reason, it doesn’t seem like UserInputService is able to get the inputs of the arrow keys while the player is focused on the TextBox. I’ve made sure that the function I’m using is actually connecting when I need it to, as well as testing to see if it will register when other keys are used (I tested ‘W’ and ‘PageDown’), yet nothing seems to work. Does focusing a TextBox take priority over UserInputService, or is there a way for me to have both of them work at the same time?
1 Like
It’s most likely because you’re returning your .InputBegan function when it sees gameProccessedEvent. gameProccessedEvent is true when you’re focused on a TextBox, so this could be why it’s not registering anything.
If you could show your script, that would help.
1 Like
here’s the important bits of my script
msgBox = script.Parent.CommandLine.CommandInput
local historySize = 10
local commandHistory = { }
local seekIndex = 0
local connection
local function seekHistory(input, _gameProcessed)
if input.UserInputType == Enum.KeyCode.Up then
if #commandHistory > 0 and seekIndex < historySize then
seekIndex += 1
msgBox.Text = commandHistory[seekIndex]
end
elseif input.UserInputType == Enum.KeyCode.Down then
if #commandHistory > 0 and seekIndex >= 1 then
seekIndex -= 1
if seekIndex ~= 0 then
msgBox.Text = commandHistory[seekIndex]
else
msgBox.Text = ""
end
end
end
end
msgBox.Focused:Connect(function()
connection = UserInputService.InputBegan:Connect(seekHistory)
end)
msgBox.FocusLost:Connect(function(enter)
connection:Disconnect()
if enter then
--command stuff here
end
I figured it would be less resource-intensive to have the seeking function only be connected while the box is focused, although I may be wrong about that