Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Player = game.Players.LocalPlayer
- local TextBox = script.Parent
- local blinker = script.Parent.blinker
- local UIS = game:GetService("UserInputService")
- local TextS = game:GetService("TextService")
- local Focused
- local LShift
- local Exceptions
- Exceptions = {
- Add = function(...)
- for _,Input in pairs({...}) do
- Exceptions[Input] = true
- end
- end
- }
- Exceptions.Add("G")
- function blinkerHandler()
- while true do
- wait(.35)
- if Focused then
- blinker.Visible = true
- end
- wait(.35)
- blinker.Visible = false
- end
- end
- local blink = coroutine.wrap(blinkerHandler)
- blink()
- local lastTextSize
- local lineCount = 1
- local lineLengths = {}
- UIS.InputBegan:Connect(function(InputObject, gameProcessed)
- if InputObject.KeyCode == Enum.KeyCode.LeftShift then
- LShift = true
- elseif InputObject.UserInputType == Enum.UserInputType.Keyboard and Focused then
- if Exceptions[InputObject.KeyCode.Name] or string.len(InputObject.KeyCode.Name) ~= 1 then return end
- local Pressed = true
- UIS.InputEnded:Connect(function(InputObject2, gameProcessed2)
- Pressed = false
- end)
- wait(.2)
- if Pressed then
- repeat
- wait()
- TextBox.Text = TextBox.Text .. (LShift and InputObject.KeyCode.Name or string.lower(InputObject.KeyCode.Name))
- blinker.Position = UDim2.new(.5,0,.5,-8) + UDim2.new(0,0,0,TextBox.TextBounds.Y-TextBox.TextSize)
- if TextBox.TextBounds.X/2 == lastTextSize and lineCount == 1 then
- print("reached line 2")
- lineLengths[lineCount] = {Size = TextS:GetTextSize(TextBox.Text, TextBox.TextSize, TextBox.Font, TextBox.AbsoluteSize); Length = string.len(TextBox.Text)-1}
- lineCount = lineCount + 1
- else
- if lineLengths[1] then
- local totalTextSize = 0
- local totalTextLength = 0
- for _,Line in pairs(lineLengths) do
- totalTextSize = totalTextSize + Line.Size.X
- totalTextLength = totalTextLength + Line.Length
- end
- local croppedtext = string.sub(TextBox.Text, totalTextLength)
- local textsize = TextS:GetTextSize(croppedtext, TextBox.TextSize, TextBox.Font, TextBox.AbsoluteSize)
- local textlength = string.len(croppedtext)
- blinker.Position = blinker.Position + UDim2.new(0,textsize.X/2,0,0)
- if lastTextSize-totalTextSize == textsize.X then
- print("reached line", lineCount + 1)
- lineLengths[lineCount] = {Size = textsize; Length = textlength}
- lineCount = lineCount + 1
- end
- lastTextSize = totalTextSize + textsize.X
- else
- lastTextSize = TextBox.TextBounds.X/2
- blinker.Position = blinker.Position + UDim2.new(0,TextBox.TextBounds.X/2,0,0)
- end
- end
- if TextBox.TextBounds.Y-TextBox.TextSize > 0 then
- local padding = ((TextBox.TextBounds.Y-TextBox.TextSize)/TextBox.TextSize)*7
- blinker.Position = blinker.Position - UDim2.new(0,0,0,padding)
- end
- until not Pressed
- end
- end
- end)
- UIS.InputEnded:Connect(function(InputObject, gameProcessed)
- if InputObject.KeyCode == Enum.KeyCode.Return then
- Player.Character.Humanoid.WalkSpeed = 16
- Player.Character.Humanoid.JumpPower = 50
- Focused = false
- elseif InputObject.KeyCode == Enum.KeyCode.LeftShift then
- LShift = false
- elseif InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
- if Focused and not gameProcessed then
- Player.Character.Humanoid.WalkSpeed = 16
- Player.Character.Humanoid.JumpPower = 50
- Focused = false
- end
- elseif InputObject.KeyCode == Enum.KeyCode.Backspace and Focused then
- TextBox.Text = string.sub(TextBox.Text, 1, string.len(TextBox.Text)-1)
- blinker.Position = UDim2.new(.5,0,.5,-8) + UDim2.new(0,0,0,TextBox.TextBounds.Y-TextBox.TextSize)
- if TextBox.TextBounds.X/2 == lastTextSize and lineCount == 1 then
- print("reached line 2")
- lineLengths[lineCount] = {Size = TextS:GetTextSize(TextBox.Text, TextBox.TextSize, TextBox.Font, TextBox.AbsoluteSize); Length = string.len(TextBox.Text)-1}
- lineCount = lineCount + 1
- else
- if lineLengths[1] then
- local totalTextSize = 0
- local totalTextLength = 0
- for _,Line in pairs(lineLengths) do
- totalTextSize = totalTextSize + Line.Size.X
- totalTextLength = totalTextLength + Line.Length
- end
- local croppedtext = string.sub(TextBox.Text, totalTextLength)
- local textsize = TextS:GetTextSize(croppedtext, TextBox.TextSize, TextBox.Font, TextBox.AbsoluteSize)
- local textlength = string.len(croppedtext)
- blinker.Position = blinker.Position + UDim2.new(0,textsize.X/2,0,0)
- if lastTextSize-totalTextSize == textsize.X then
- print("reached line", lineCount + 1)
- lineLengths[lineCount] = {Size = textsize; Length = textlength}
- lineCount = lineCount + 1
- end
- lastTextSize = totalTextSize + textsize.X
- else
- lastTextSize = TextBox.TextBounds.X/2
- blinker.Position = blinker.Position + UDim2.new(0,TextBox.TextBounds.X/2,0,0)
- end
- end
- if TextBox.TextBounds.Y-TextBox.TextSize > 0 then
- local padding = ((TextBox.TextBounds.Y-TextBox.TextSize)/TextBox.TextSize)*7
- blinker.Position = blinker.Position - UDim2.new(0,0,0,padding)
- end
- elseif InputObject.UserInputType == Enum.UserInputType.Keyboard and Focused then
- if Exceptions[InputObject.KeyCode.Name] or string.len(InputObject.KeyCode.Name) ~= 1 then return end
- TextBox.Text = TextBox.Text .. (LShift and InputObject.KeyCode.Name or string.lower(InputObject.KeyCode.Name))
- blinker.Position = UDim2.new(.5,0,.5,-8) + UDim2.new(0,0,0,TextBox.TextBounds.Y-TextBox.TextSize)
- if TextBox.TextBounds.X/2 == lastTextSize and lineCount == 1 then
- print("reached line 2")
- lineLengths[lineCount] = {Size = TextS:GetTextSize(TextBox.Text, TextBox.TextSize, TextBox.Font, TextBox.AbsoluteSize); Length = string.len(TextBox.Text)-1}
- lineCount = lineCount + 1
- else
- if lineLengths[1] then
- local totalTextSize = 0
- local totalTextLength = 0
- for _,Line in pairs(lineLengths) do
- totalTextSize = totalTextSize + Line.Size.X
- totalTextLength = totalTextLength + Line.Length
- end
- local croppedtext = string.sub(TextBox.Text, totalTextLength)
- local textsize = TextS:GetTextSize(croppedtext, TextBox.TextSize, TextBox.Font, TextBox.AbsoluteSize)
- local textlength = string.len(croppedtext)
- blinker.Position = blinker.Position + UDim2.new(0,textsize.X/2,0,0)
- if lastTextSize-totalTextSize == textsize.X then
- print("reached line", lineCount + 1)
- lineLengths[lineCount] = {Size = textsize; Length = textlength}
- lineCount = lineCount + 1
- end
- lastTextSize = totalTextSize + textsize.X
- else
- lastTextSize = TextBox.TextBounds.X/2
- blinker.Position = blinker.Position + UDim2.new(0,TextBox.TextBounds.X/2,0,0)
- end
- end
- if TextBox.TextBounds.Y-TextBox.TextSize > 0 then
- local padding = ((TextBox.TextBounds.Y-TextBox.TextSize)/TextBox.TextSize)*7
- blinker.Position = blinker.Position - UDim2.new(0,0,0,padding)
- end
- end
- end)
- TextBox.InputBegan:Connect(function(InputObject)
- if InputObject.UserInputType == Enum.UserInputType.MouseButton1 then
- if not Focused then
- wait(.1)
- TextBox.Text = ""
- blinker.Position = UDim2.new(.5,0,.5,-8)
- lineCount = 1
- lastTextSize = nil
- lineLengths = {}
- Player.Character.Humanoid.WalkSpeed = 0
- Player.Character.Humanoid.JumpPower = 0
- Focused = true
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement