I've been trying to make a (RELATIVELY!) simple ScreenGui for making scripts and running them in-game via loadstring. I've mainly been working on the script to add/delete lines, and I'm having trouble deleting them. So, I make some random lines swiping my fingers on the keyboard and spamming enter. Then, I pause. I'm on maybe line 12 or so. The current line says "asdf". I press backspace four times, and rather than emptying the line, the script deletes the line and leaves the line above it blank. That's not what I want, I just want to clear up the line. How do I prevent this?
Script:
lineframe = script.Parent.Parent CurrentLine = script.Parent CurrentLineNumber = tonumber(string.sub(script.Parent.Name, 5)) NewLineNumber = CurrentLineNumber + 1 InputService = game:GetService("UserInputService") script.Parent.FocusLost:connect(function(enter) if enter then for i = NewLineNumber, #lineframe:GetChildren() do lineframe["Line"..i].Name = "Line"..i + 1 lineframe["Line"..i + 1].Position = UDim2.new(0, 0, 0, i * 20) end local newline = Instance.new("TextBox", lineframe) newline.Name = "Line"..NewLineNumber newline.Size = UDim2.new(0, 400, 0, 20) newline.Position = UDim2.new(0, 0, 0, CurrentLineNumber * 20) newline.BackgroundColor3 = Color3.new(1, 1, 1) newline.Font = Enum.Font.SourceSans newline.FontSize = Enum.FontSize.Size24 newline.TextXAlignment = Enum.TextXAlignment.Left newline.Text = "" local linescript = script:Clone() linescript.Parent = newline newline:CaptureFocus() end end) CurrentLine.Focused:connect(function() InputService.InputBegan:connect(function(input) if input.KeyCode == Enum.KeyCode.Backspace and CurrentLine.Name ~= "Line1" and CurrentLine.Text == "" then lineframe["Line"..CurrentLineNumber - 1]:CaptureFocus() for i = NewLineNumber, #lineframe:GetChildren() do lineframe["Line"..i].Name = "Line"..i - 1 end CurrentLine:Destroy() end end) end)
Hierarchy: http://imgur.com/iyvwtDo