Advertisement
Guest User

xx

a guest
Feb 19th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.42 KB | None | 0 0
  1. local Player = game.Players.LocalPlayer
  2.  
  3. local TextBox = script.Parent
  4. local blinker = script.Parent.blinker
  5.  
  6. local UIS = game:GetService("UserInputService")
  7. local TextS = game:GetService("TextService")
  8.  
  9. local Focused
  10. local LShift
  11.  
  12. local Exceptions
  13.  
  14. Exceptions = {
  15.     Add = function(...)
  16.         for _,Input in pairs({...}) do
  17.             Exceptions[Input] = true
  18.         end
  19.     end
  20. }
  21.  
  22. Exceptions.Add("G")
  23.  
  24. function blinkerHandler()
  25.     while true do
  26.         wait(.35)
  27.         if Focused then
  28.             blinker.Visible = true
  29.         end
  30.         wait(.35)
  31.         blinker.Visible = false
  32.     end
  33. end
  34.  
  35. local blink = coroutine.wrap(blinkerHandler)
  36. blink()
  37.  
  38. local lastTextSize
  39. local lineCount = 1
  40. local lineLengths = {}
  41.  
  42. UIS.InputBegan:Connect(function(InputObject, gameProcessed)
  43.     if InputObject.KeyCode == Enum.KeyCode.LeftShift then
  44.         LShift = true
  45.     elseif InputObject.UserInputType == Enum.UserInputType.Keyboard and Focused then
  46.         if Exceptions[InputObject.KeyCode.Name] or string.len(InputObject.KeyCode.Name) ~= 1 then return end
  47.        
  48.         local Pressed = true
  49.        
  50.         UIS.InputEnded:Connect(function(InputObject2, gameProcessed2)
  51.             Pressed = false
  52.         end)
  53.        
  54.         wait(.2)
  55.        
  56.         if Pressed then
  57.             repeat
  58.                 wait()
  59.                 TextBox.Text = TextBox.Text .. (LShift and InputObject.KeyCode.Name or string.lower(InputObject.KeyCode.Name))
  60.                 blinker.Position = UDim2.new(.5,0,.5,-8) + UDim2.new(0,0,0,TextBox.TextBounds.Y-TextBox.TextSize)
  61.                 if TextBox.TextBounds.X/2 == lastTextSize and lineCount == 1 then
  62.                     print("reached line 2")
  63.                     lineLengths[lineCount] = {Size = TextS:GetTextSize(TextBox.Text, TextBox.TextSize, TextBox.Font, TextBox.AbsoluteSize); Length = string.len(TextBox.Text)-1}
  64.                     lineCount = lineCount + 1
  65.                 else
  66.                     if lineLengths[1] then
  67.                         local totalTextSize = 0
  68.                         local totalTextLength = 0
  69.                        
  70.                         for _,Line in pairs(lineLengths) do
  71.                             totalTextSize = totalTextSize + Line.Size.X
  72.                             totalTextLength = totalTextLength + Line.Length
  73.                         end
  74.                        
  75.                         local croppedtext = string.sub(TextBox.Text, totalTextLength)
  76.                         local textsize = TextS:GetTextSize(croppedtext, TextBox.TextSize, TextBox.Font, TextBox.AbsoluteSize)
  77.                         local textlength = string.len(croppedtext)
  78.                        
  79.                         blinker.Position = blinker.Position + UDim2.new(0,textsize.X/2,0,0)
  80.                                        
  81.                         if lastTextSize-totalTextSize == textsize.X then
  82.                             print("reached line", lineCount + 1)
  83.                             lineLengths[lineCount] = {Size = textsize; Length = textlength}
  84.                             lineCount = lineCount + 1
  85.                         end
  86.                        
  87.                         lastTextSize = totalTextSize + textsize.X
  88.                     else
  89.                         lastTextSize = TextBox.TextBounds.X/2
  90.                         blinker.Position = blinker.Position + UDim2.new(0,TextBox.TextBounds.X/2,0,0)
  91.                     end
  92.                 end
  93.                
  94.                 if TextBox.TextBounds.Y-TextBox.TextSize > 0 then
  95.                     local padding = ((TextBox.TextBounds.Y-TextBox.TextSize)/TextBox.TextSize)*7
  96.                     blinker.Position = blinker.Position - UDim2.new(0,0,0,padding)
  97.                 end
  98.             until not Pressed
  99.         end
  100.     end
  101. end)
  102.  
  103. UIS.InputEnded:Connect(function(InputObject, gameProcessed)
  104.     if InputObject.KeyCode == Enum.KeyCode.Return then
  105.         Player.Character.Humanoid.WalkSpeed = 16
  106.         Player.Character.Humanoid.JumpPower = 50
  107.         Focused = false
  108.     elseif InputObject.KeyCode == Enum.KeyCode.LeftShift then
  109.         LShift = false
  110.     elseif InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
  111.         if Focused and not gameProcessed then
  112.             Player.Character.Humanoid.WalkSpeed = 16
  113.             Player.Character.Humanoid.JumpPower = 50
  114.             Focused = false
  115.         end
  116.     elseif InputObject.KeyCode == Enum.KeyCode.Backspace and Focused then
  117.         TextBox.Text = string.sub(TextBox.Text, 1, string.len(TextBox.Text)-1)
  118.         blinker.Position = UDim2.new(.5,0,.5,-8) + UDim2.new(0,0,0,TextBox.TextBounds.Y-TextBox.TextSize)
  119.         if TextBox.TextBounds.X/2 == lastTextSize and lineCount == 1 then
  120.             print("reached line 2")
  121.             lineLengths[lineCount] = {Size = TextS:GetTextSize(TextBox.Text, TextBox.TextSize, TextBox.Font, TextBox.AbsoluteSize); Length = string.len(TextBox.Text)-1}
  122.             lineCount = lineCount + 1
  123.         else
  124.             if lineLengths[1] then
  125.                 local totalTextSize = 0
  126.                 local totalTextLength = 0
  127.                
  128.                 for _,Line in pairs(lineLengths) do
  129.                     totalTextSize = totalTextSize + Line.Size.X
  130.                     totalTextLength = totalTextLength + Line.Length
  131.                 end
  132.                
  133.                 local croppedtext = string.sub(TextBox.Text, totalTextLength)
  134.                 local textsize = TextS:GetTextSize(croppedtext, TextBox.TextSize, TextBox.Font, TextBox.AbsoluteSize)
  135.                 local textlength = string.len(croppedtext)
  136.                
  137.                 blinker.Position = blinker.Position + UDim2.new(0,textsize.X/2,0,0)
  138.                                
  139.                 if lastTextSize-totalTextSize == textsize.X then
  140.                     print("reached line", lineCount + 1)
  141.                     lineLengths[lineCount] = {Size = textsize; Length = textlength}
  142.                     lineCount = lineCount + 1
  143.                 end
  144.                
  145.                 lastTextSize = totalTextSize + textsize.X
  146.             else
  147.                 lastTextSize = TextBox.TextBounds.X/2
  148.                 blinker.Position = blinker.Position + UDim2.new(0,TextBox.TextBounds.X/2,0,0)
  149.             end
  150.         end
  151.        
  152.         if TextBox.TextBounds.Y-TextBox.TextSize > 0 then
  153.             local padding = ((TextBox.TextBounds.Y-TextBox.TextSize)/TextBox.TextSize)*7
  154.             blinker.Position = blinker.Position - UDim2.new(0,0,0,padding)
  155.         end
  156.     elseif InputObject.UserInputType == Enum.UserInputType.Keyboard and Focused then
  157.         if Exceptions[InputObject.KeyCode.Name] or string.len(InputObject.KeyCode.Name) ~= 1 then return end
  158.        
  159.         TextBox.Text = TextBox.Text .. (LShift and InputObject.KeyCode.Name or string.lower(InputObject.KeyCode.Name))
  160.        
  161.         blinker.Position = UDim2.new(.5,0,.5,-8) + UDim2.new(0,0,0,TextBox.TextBounds.Y-TextBox.TextSize)
  162.        
  163.         if TextBox.TextBounds.X/2 == lastTextSize and lineCount == 1 then
  164.             print("reached line 2")
  165.             lineLengths[lineCount] = {Size = TextS:GetTextSize(TextBox.Text, TextBox.TextSize, TextBox.Font, TextBox.AbsoluteSize); Length = string.len(TextBox.Text)-1}
  166.             lineCount = lineCount + 1
  167.         else
  168.             if lineLengths[1] then
  169.                 local totalTextSize = 0
  170.                 local totalTextLength = 0
  171.                
  172.                 for _,Line in pairs(lineLengths) do
  173.                     totalTextSize = totalTextSize + Line.Size.X
  174.                     totalTextLength = totalTextLength + Line.Length
  175.                 end
  176.                
  177.                 local croppedtext = string.sub(TextBox.Text, totalTextLength)
  178.                 local textsize = TextS:GetTextSize(croppedtext, TextBox.TextSize, TextBox.Font, TextBox.AbsoluteSize)
  179.                 local textlength = string.len(croppedtext)
  180.                
  181.                 blinker.Position = blinker.Position + UDim2.new(0,textsize.X/2,0,0)
  182.                                
  183.                 if lastTextSize-totalTextSize == textsize.X then
  184.                     print("reached line", lineCount + 1)
  185.                     lineLengths[lineCount] = {Size = textsize; Length = textlength}
  186.                     lineCount = lineCount + 1
  187.                 end
  188.                
  189.                 lastTextSize = totalTextSize + textsize.X
  190.             else
  191.                 lastTextSize = TextBox.TextBounds.X/2
  192.                 blinker.Position = blinker.Position + UDim2.new(0,TextBox.TextBounds.X/2,0,0)
  193.             end
  194.         end
  195.        
  196.         if TextBox.TextBounds.Y-TextBox.TextSize > 0 then
  197.             local padding = ((TextBox.TextBounds.Y-TextBox.TextSize)/TextBox.TextSize)*7
  198.             blinker.Position = blinker.Position - UDim2.new(0,0,0,padding)
  199.         end
  200.     end
  201. end)
  202.  
  203. TextBox.InputBegan:Connect(function(InputObject)
  204.     if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
  205.         if not Focused then
  206.             wait(.1)
  207.             TextBox.Text = ""
  208.             blinker.Position = UDim2.new(.5,0,.5,-8)
  209.             lineCount = 1
  210.             lastTextSize = nil
  211.             lineLengths = {}
  212.             Player.Character.Humanoid.WalkSpeed = 0
  213.             Player.Character.Humanoid.JumpPower = 0
  214.             Focused = true
  215.         end
  216.     end
  217. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement