Hello! So I am making a In-Studio Script executor plugin and am trying to implement Auto indentation but am unsure how. I have tried stuff like this:
CodeBox.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.Return then
print("Testing")
end
end
end)
But it doesn’t seem to work. I’ve looked this up many times and wasn’t able to find anything.
I thought of FocusLost except I don’t want it to exit the textbox, just add an indent like it would in the script editor. Thanks for the suggestion though!
The ‘Return’ key automatically releases the textbox’s focus, here’s a script to achieve what you’re trying to achieve though.
local script = script
local textBox = script.Parent
textBox.ClearTextOnFocus = false --This is necessary (can be done in the properties window).
local function onTextBoxFocusLost(enterPressed, inputObject)
if enterPressed then
textBox.Text..="\n"
textBox:CaptureFocus()
end
end
textBox.FocusLost:Connect(onTextBoxFocusLost)
That partially worked. Except for some reason it only did it when I pressed backspace and when I would press backspace again it would go back one line with one less space. But I think this method could work. Thanks!